Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:用C++STL写好容易超时啊In Reply To:用C++STL写好容易超时啊 Posted by:undiaoyao at 2006-12-20 20:02:47 用map<int, int>好点吧 > C++STL写思路蛮自然也方便……就是超时得厉害 > 郁闷…… > > #include <iostream> > #include <vector> > #include <map> > > using namespace std; > > void delcon(string &str) > { > int index = 0; > while(index < str.length()) > { > if(str[index] == '-') > { > str.erase(index,1); > continue; > } > ++index; > } > } > > void pout_book(map<string, int> telbook) > { > map<string, int>::iterator bookIter = telbook.begin(); > for(;bookIter != telbook.end(); ++bookIter) > { > string tempStr = bookIter->first; > if(bookIter->second>1) > { > tempStr.insert(3,"-"); > cout<<tempStr<<" "<<bookIter->second<<endl; > } > } > } > > void trance(string &str) > { > for(int index=0; index < str.length(); ++index) > { > switch(str[index]){ > case 'A':case 'B':case 'C': > (str[index]) = '2';break; > case 'D':case 'E':case 'F': > (str[index]) = '3';break; > case 'G':case 'H':case 'I': > (str[index]) = '4';break; > case 'J':case 'K':case 'L': > (str[index]) = '5';break; > case 'M':case 'N':case 'O': > (str[index]) = '6';break; > case 'P':case 'R':case 'S': > (str[index]) = '7';break; > case 'T':case 'U':case 'V': > (str[index]) = '8';break; > case 'W':case 'X':case 'Y': > (str[index]) = '9';break; > default:break; > } > } > } > > int main() > { > int turns = 0; > map<string,int> telBook; > cin>>turns; > for(;turns > 0; --turns) > { > string curStr(""); > cin>>curStr; > delcon(curStr); > trance(curStr); > ++telBook[curStr]; > } > pout_book(telBook); > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator