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 |
高手,请帮一下忙,老是超时!!!!!!!!!!!!!!1002 1002 1002 1002#include <iostream> #include <stdlib.h> #include <string> using namespace std; char getNumber(char c){ switch(c){ case 'A': case 'B': case 'C': return '2'; break; case 'D': case 'E': case 'F': return '3'; break; case 'G': case 'H': case 'I': return '4'; break; case 'J': case 'K': case 'L': return '5'; break; case 'M': case 'N': case 'O': return '6'; break; case 'P': case 'R': case 'S': return '7'; break; case 'T': case 'U': case 'V': return '8'; break; case 'W': case 'X': case 'Y': return '9'; break; } } int main(int argc, char *argv[]) { int i,j,digit,temp,flag[100000],add[100000]; char c,str[100000][9]; cin>>digit; for( i=0;i<digit;i++){ for(j=0;j<8;j++){ if(j==3){ str[i][j]='-'; continue; } cin>>c; while(c=='-') cin>>c; if(c!='-'){ if((c>='0')&&(c<='9')){ str[i][j]=c; } else str[i][j]=getNumber(c); } } str[i][8]='\0'; } for(i=0;i<digit;i++){ flag[i]=1; add[i]=i; } for(i=0;i<digit;i++) if(flag[i]!=0) for(j=i+1;j<digit;j++) if(flag[j]!=0) if(!strcmp(str[i],str[j])){ ++flag[i]; flag[j]=0; } for(i=0;i<digit;i++) if(flag[i]>1){ for(j=i+1;j<digit;j++) if((flag[j]>1)&&strcmp(str[add[i]],str[add[j]])>0){ temp=add[i];add[i]=add[j]; add[j]=temp; temp=flag[i];flag[i]=flag[j];flag[j]=temp; } } for(i=0,j=0;i<digit;i++) if(flag[i]>1){ cout<<str[add[i]]<<" "<<flag[i]<<endl; ++j; } if(j==0) cout<<"No duplicates."<<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