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 |
我的也超时,试了三次还是不行,一起研究研究。。。(G++)In Reply To:怎么还会超时呢,已经用快排了。 Posted by:412188290 at 2010-12-27 16:27:21 #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> using namespace std; //#define FILE_DATA #define forn(i,n) for(int i=0;i<n;i++) char code[27]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char num[27] ="22233344455566677778889999"; char findNumFormCode(char c) { return num[c-'A']; } int compare (const void * a, const void * b) { return strcmp((const char *)a,(const char *)b); } int main() { #ifdef FILE_DATA char fileName[]="practice"; char inFileName[50]; char outFileName[50]; strcpy(inFileName,fileName); strcpy(outFileName,fileName); strcat(inFileName,".in"); strcat(outFileName,".out"); FILE* ifp=freopen(inFileName,"r",stdin); if(ifp==NULL) return 1; #endif char line[128]; int T; int len; char c; cin>>T; char result[T][9]; forn(i,T) memset(result[i],0,9); // char tmp[9]; int index; forn(i,T) { index=0; cin>>line; // cout<<line<<endl; len=strlen(line); forn(j,len) { c=line[j]; if(isalpha(c)) { result[i][index++]=findNumFormCode(c); } else if(isdigit(c)) { result[i][index++]=c; } if(index==3) result[i][index++]='-'; } // cout<<result[i]<<endl; } //排序 qsort(result,T,sizeof(result[0]),compare); // forn(i,T) // { // // for(int j=i+1; j<T; j++) // { // if(strcmp(result[i],result[j])>0) // { // strcpy(tmp,result[i]); // strcpy(result[i],result[j]); // strcpy(result[j],tmp); // } // } // } bool bFind=false; int count; forn(i,T) { count=1; for(int j=i+1; j<T; j++) { if(result[j][0]!='-'&&strcmp(result[i],result[j])==0) { bFind=true; count++; result[j][0]='-'; } } if(count>1) cout<<result[i]<<" "<<count<<endl; // // } if(!bFind) cout<<"No duplicates."<<endl; #ifdef FILE_DATA fclose(ifp); #endif return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator