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<map> #include<stdio.h> #include<stdlib.h> #define MAXSIZE 100 using namespace std; int main(void) { int n; scanf("%d",&n); string str; string s; map<string,int> m; char ch[MAXSIZE]="222333444555666777888999"; while(n--) { cin>>str; int length=str.length(); int count=0; s=""; for(int i=0;i<length;i++) { if(str[i]=='-') { continue; } else if(str[i]>='A'&&str[i]<='Y') { /* A, B, and C map to 2 D, E, and F map to 3 G, H, and I map to 4 J, K, and L map to 5 M, N, and O map to 6 P, R, and S map to 7 T, U, and V map to 8 W, X, and Y map to 9 */ if(str[i]>='R'&&str[i]<='Y') { s=s+ch[str[i]-'A'-1]; } else { s=s+ch[str[i]-'A']; } } else { s=s+str[i]; } count++; if(count==3) { s=s+'-'; } } m[s]++; } for(map<string,int>::iterator it=m.begin();it!=m.end();it++) { if(it->second>1) { cout<<it->first<<' '<<it->second<<endl; } } //system("pause"); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator