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 |
各位大虾,帮忙看一下code为什么WA。(C++&STL)#include <map> #include <string> #include <iostream> #include <stdio.h> using namespace std; char GetNumber(char a); int main() { int cases; cin>>cases; map<string,int> map1; for(int i=0;i<cases;i++) { string s; cin>>s; int len=s.length(); string str=""; char tmp; int sign=0; for(int j=0;j<len;j++) { tmp=GetNumber(s[j]); if(tmp==0) continue; if(sign==3) str+='-'; str+=tmp; ++sign; } if(map1.find(str)!=map1.end()) { ++map1[str]; } else { map1[str]=1; } } map<string,int>::iterator iter=map1.begin(); while(iter!=map1.end()) { if((*iter).second>1) { cout<<(*iter).first<<" "<<(*iter).second<<endl; } ++iter; } return 0; } //helper function char GetNumber(char a) { if(a=='-') return 0; if(a>='0' && a<='9') return a; if(a=='A' || a=='B' || a=='C') return '2'; if(a=='D' || a=='E' || a=='F') return '3'; if(a=='G' || a=='H' || a=='I') return '4'; if(a=='J' || a=='K' || a=='L') return '5'; if(a=='M' || a=='N' || a=='O') return '6'; if(a=='P' || a=='R' || a=='S') return '7'; if(a=='T' || a=='U' || a=='V') return '8'; if(a=='W' || a=='X' || a=='Y') return '9'; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator