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 |
注意:用C++比G++快的多 using STL代码效率不高 可以AC 写起来还简单 没思考太多东西吧 #include <map> #include <iterator> #include <iostream> #include <string> using namespace std; string StandardForm(string OneCode); int main() { int num; bool ExistDulp=false; string OneCode,StandardCode; cin>>num; map<string, int> TeleNumber; map<string, int>::iterator OneTeleNumber; while(num--) { cin>>OneCode; StandardCode=StandardForm(OneCode); OneTeleNumber=TeleNumber.find(StandardCode); if(OneTeleNumber==TeleNumber.end()) { TeleNumber.insert(pair<string,int>(StandardCode,1)); } else { (OneTeleNumber->second)++; } } for(OneTeleNumber=TeleNumber.begin(); OneTeleNumber!=TeleNumber.end();OneTeleNumber++) { if(OneTeleNumber->second!=1) { cout<<OneTeleNumber->first<<" "<<OneTeleNumber->second<<endl; ExistDulp=true; } } if(!ExistDulp) { cout<<"No duplicates."<<endl; } return 0; } string StandardForm(string OneCode) { for(int i=0;i<OneCode.length();i++) { if(OneCode[i]=='A'||OneCode[i]=='B'||OneCode[i]=='C') OneCode[i]='2'; else if(OneCode[i]=='D'||OneCode[i]=='E'||OneCode[i]=='F') OneCode[i]='3'; else if(OneCode[i]=='G'||OneCode[i]=='H'||OneCode[i]=='I') OneCode[i]='4'; else if(OneCode[i]=='J'||OneCode[i]=='K'||OneCode[i]=='L') OneCode[i]='5'; else if(OneCode[i]=='M'||OneCode[i]=='N'||OneCode[i]=='O') OneCode[i]='6'; else if(OneCode[i]=='P'||OneCode[i]=='R'||OneCode[i]=='S') OneCode[i]='7'; else if(OneCode[i]=='T'||OneCode[i]=='U'||OneCode[i]=='V') OneCode[i]='8'; else if(OneCode[i]=='W'||OneCode[i]=='X'||OneCode[i]=='Y') OneCode[i]='9'; else if(OneCode[i]=='-') { OneCode.erase(i,1); i--; } } OneCode.insert(3,"-"); return OneCode; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator