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 |
哪里出错了呢?Source Code #include <iostream> #include <string> #include <map> #include <utility> using namespace std; int main() { map<string,int> database; map<string,int>::iterator iter; string current; string newdata; char temp[2]; int counter; bool flag=0; temp[1]=0; cin>>counter; while(counter--){ cin>>current; newdata.assign(""); for(int i=0;i<current.length();++i){ switch(current[i]) { case '0': temp[0]='0'; newdata.append(temp); break; case '1': temp[0]='1'; newdata.append(temp); break; case 'A': case 'B': case 'C': case '2': temp[0]='2'; newdata.append(temp); break; case 'D': case 'E': case 'F': case '3': temp[0]='3'; newdata.append(temp); break; case 'G': case 'H': case 'I': case '4': temp[0]='4'; newdata.append(temp); break; case 'J': case 'K': case 'L': case '5': temp[0]='5'; newdata.append(temp); break; case 'M': case 'N': case 'O': case '6': temp[0]='6'; newdata.append(temp); break; case 'P': case 'R': case 'S': case '7': temp[0]='7'; newdata.append(temp); break; case 'T': case 'U': case 'V': case '8': temp[0]='8'; newdata.append(temp); break; case 'W': case 'X': case 'Y': case '9': temp[0]='9'; newdata.append(temp); break; default: break; } flag=0; for(iter=database.begin();iter!=database.end();++iter) { if(iter->first==newdata) { iter->second++; flag=1; } } } if(!flag){ database.insert(make_pair<string,int>(newdata,1)); } } flag=0; for(iter=database.begin();iter!=database.end();++iter) { if(iter->second>1) { flag=1; cout<<iter->first[0]<<iter->first[1]<<iter->first[2]; cout<<"-"; cout<<iter->first[3]<<iter->first[4]<<iter->first[5]<<iter->first[6]; cout<<" "<<iter->second<<endl; } } if(!flag){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