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 |
这样的程序为什么过了所有的测试数据和discuss里面的测试数据,还是ra呢??大牛帮个忙吧!//pku1002 #include<iostream> #include<string.h> using namespace std; int judge(char ch) { if(ch>='0'&&ch<='9')return ch; else switch(ch){ 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; // default:break; } } int compare(const void *a,const void *b) { return (strcmp((char *)a,(char *)b)); } int main(){ char ch[100000][20]; int n,have=0; cin>>n; for(int i=0;i<n;i++) cin>>ch[i]; for(int i=0;i<n;i++) { int k=0; for(int j=0;j<strlen(ch[i]);j++) if(ch[i][j]!='-') ch[i][k++]=judge(ch[i][j]); ch[i][k]='\0'; for(int t=7;t>=3;t--) { ch[i][t+1]=ch[i][t]; } ch[i][3]='-'; }//全部转化为标准形式 qsort(ch,n,sizeof(ch[0]),compare);//利用qsort对字符串进行字典排序 int i=0,j,count; while(i<n) { j=i; while(j<n&&strcmp(ch[i],ch[j])==0)j++; if((j-i)>=2){cout<<ch[i]<<' '<<j-i<<endl;have=1;} if(j>=n)break; else i=j; } if(have==0)cout<<"No duplicates."; system("pause"); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator