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 |
怎么老是超时啊 那位大神能帮我看下~~~#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(){ int m,i,j,k; int count[10000]; string str; for (i=0;i<10000;i++) count[i]=1; cin>>m; vector<string> v; for (i=0;i<m;i++) { cin>>str; v.push_back(str); } for (i=0;i<m;i++)//化成标准形式 { for (j=0;v[i][j]!='\0';j++) { if(v[i][j]=='-' && j!=3) v[i]=v[i].substr(0,j)+v[i].substr(j+1,v[i].length()-j-1); else if (v[i][j]=='A' || v[i][j]=='B' || v[i][j]=='C') v[i][j]='2'; else if (v[i][j]=='D' || v[i][j]=='E' || v[i][j]=='F') v[i][j]='3'; else if (v[i][j]=='G' || v[i][j]=='H' || v[i][j]=='I') v[i][j]='4'; else if (v[i][j]=='J' || v[i][j]=='K' || v[i][j]=='L') v[i][j]='5'; else if (v[i][j]=='M' || v[i][j]=='N' || v[i][j]=='O') v[i][j]='6'; else if (v[i][j]=='P' || v[i][j]=='R' || v[i][j]=='S') v[i][j]='7'; else if (v[i][j]=='T' || v[i][j]=='U' || v[i][j]=='V') v[i][j]='8'; else if (v[i][j]=='W' || v[i][j]=='X' || v[i][j]=='Y') v[i][j]='9'; if(v[i][j]!='-' && j==3) v[i]=v[i].substr(0,3)+'-'+v[i].substr(3,v[i].length()-3); } } sort(v.begin(),v.end()); for (i=0;i<m;i++) { if(count[i]!=0) { for (j=i+1;j<m;j++) { for (k=0;v[j][k]!='\0',v[i][k]!='\0';k++) { if(v[i][k]!=v[j][k]) break; } if(k==v[j].length() &&k==v[i].length()) { count[i]++; count[j]=0; } } } } for (i=0;i<m;i++) { if(count[i]!=0 && count[i]!=1) cout<<v[i]<<' '<<count[i]<<endl; } for (i=0;i<m;i++) { if(count[i]!=1) break; } if(i==m) cout<<"No duplicates."; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator