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 |
总是RTE,请问下有什么特别要注意的地方吗?附: #include "iostream" #include "string" using namespace std; struct Ans { char str[20]; int order; }; int cmp(const void *a,const void *b) { return *(char *)a-*(char *)b; } int main() { char In[500]; int T,i,j,k; Ans Last[1000]; cin>>T; k=0; while (T) { cin>>In; j=0; char Out[20]; for (i=0;In[i]!='\0';i++) { if (In[i]>='0'&&In[i]<='9') Out[j++]=In[i]; if (In[i]>='A'&&In[i]<='Z') { switch(In[i]) { case 'A': Out[j++]='2'; break; case 'B': Out[j++]='2'; break; case 'C': Out[j++]='2'; break; case 'D': Out[j++]='3'; break; case 'E': Out[j++]='3'; break; case 'F': Out[j++]='3'; break; case 'G': Out[j++]='4'; break; case 'H': Out[j++]='4'; break; case 'I': Out[j++]='4'; break; case 'J': Out[j++]='5'; break; case 'K': Out[j++]='5'; break; case 'L': Out[j++]='5'; break; case 'M': Out[j++]='6'; break; case 'N': Out[j++]='6'; break; case 'O': Out[j++]='6'; break; case 'P': Out[j++]='7'; break; case 'R': Out[j++]='7'; break; case 'S': Out[j++]='7'; break; case 'T': Out[j++]='8'; break; case 'U': Out[j++]='8'; break; case 'V': Out[j++]='8'; break; case 'W': Out[j++]='9'; break; case 'X': Out[j++]='9'; break; case 'Y': Out[j++]='9'; break; default: break; } } } //转换 Out[j]='\0'; for (;j>=3;j--) Out[j+1]=Out[j]; Out[j+1]='-'; if (!k) { strcpy(Last[k].str,Out); Last[k].order=1; k++; } else { for (i=0;i<k;i++) { if (!strcmp(Out,Last[i].str)) { Last[i].order++; break; } if(i==k-1) { strcpy(Last[k].str,Out); Last[k].order=1; k++; break; } } } T--; } j=1; qsort(Last,k,sizeof(Last[0]),cmp); for (i=0;i<k;i++) { if (Last[i].order>1) { cout<<Last[i].str<<" "<<Last[i].order<<endl; j=0; } } if (j) { 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