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 |
嗯。我也是这么写的。不知道是哪部分用的时间比较多?In Reply To:用C++STL写好容易超时啊 Posted by:undiaoyao at 2006-12-20 20:02:47 是iterator还是map? #include <iostream> #include <string> #include <map> using namespace std; string to_tel_num(const string& str){ string tel_num; for(int i=0;i<str.size();i++){ if(tel_num.size() == 3) tel_num.append("-"); switch(str[i]){ case '-': break; case '0': tel_num.append("0"); break; case '1': tel_num.append("1"); break; case 'A': case 'B': case 'C': case '2': tel_num.append("2"); break; case 'D': case 'E': case 'F': case '3': tel_num.append("3"); break; case 'G': case 'H': case 'I': case '4': tel_num.append("4"); break; case 'J': case 'K': case 'L': case '5': tel_num.append("5"); break; case 'M': case 'N': case 'O': case '6': tel_num.append("6"); break; case 'P': case 'R': case 'S': case '7': tel_num.append("7"); break; case 'T': case 'U': case 'V': case '8': tel_num.append("8"); break; case 'W': case 'X': case 'Y': case '9': tel_num.append("9"); break; default: cerr<<"Error string!"<<endl; } } return tel_num; } int main(int argc, char** argv){ int n; string tel_num_str; map<string,int> tel_num_map; bool has_out = false; if(!(cin>>n)) return 1; for(int i=0;i<n;i++){ if(!(cin>>tel_num_str)) return 1; tel_num_map[to_tel_num(tel_num_str)]++; } for(map<string,int>::iterator iter = tel_num_map.begin(); iter != tel_num_map.end(); iter++) { if(iter->second !=1 ){ has_out = true; cout<<iter->first<<" "<<iter->second<<endl; } } if(!has_out) cout<<"No duplicates."<<endl; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator