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题总是不对?用gcc编译: #include"stdio.h" #include"stdlib.h" #include"string.h" /***************主程序**********************/ int main() { unsigned char tel[100000][19]; int n,i,k,s=0,j,m,h=0; int flag1[100000]={0},flag2[100000]; char temp[19]; int flag3[100000]={0}; int tem; printf("please input n:");//确定号码个数 scanf("%d",&m); for(i=0;i<m;i++) scanf("%s",&tel[i]);//输入号码 /*****************处理号码使之为标准号码****************/ for(i=0;i<m;i++) { for(n=0;n<19;n++) { if(tel[i][n]=='-') for(k=n;k<19;k++) tel[i][k]=tel[i][k+1]; } for(n=0;n<7;n++) { if(tel[i][n]=='A'||tel[i][n]=='B'||tel[i][n]=='C') tel[i][n]='2'; else if(tel[i][n]=='D'||tel[i][n]=='E'||tel[i][n]=='F') tel[i][n]='3'; else if(tel[i][n]=='G'||tel[i][n]=='H'||tel[i][n]=='I') tel[i][n]='4'; else if(tel[i][n]=='J'||tel[i][n]=='K'||tel[i][n]=='L') tel[i][n]='5'; else if(tel[i][n]=='M'||tel[i][n]=='N'||tel[i][n]=='O') tel[i][n]='6'; else if(tel[i][n]=='P'||tel[i][n]=='R'||tel[i][n]=='S') tel[i][n]='7'; else if(tel[i][n]=='T'||tel[i][n]=='U'||tel[i][n]=='V') tel[i][n]='8'; else if(tel[i][n]=='W'||tel[i][n]=='X'||tel[i][n]=='Y') tel[i][n]='9'; } } for(i=0;i<m;i++) { if(tel[i][3]!='-') { for(j=16;j>=3;j--) tel[i][j+1]=tel[i][j]; tel[i][3]='-'; } } /*************查找是否有雷同号码*********************/ for(i=0;i<m-1;i++) { int flag=1; if(flag3[i]==1) continue; {for(k=i+1;k<m;k++) if((strcmp(tel[i],tel[k]))==0) { flag++; s++; flag3[k]=1; } if(flag!=1) { flag1[h]=i; flag2[h]=flag; h++; } } } if(s==0) { printf("No duplicates"); exit(0); } else { for(i=0;i<h;i++) for(k=i+1;k<h;k++) if((strcmp(tel[flag1[i]],tel[flag1[k]]))>0) { strcpy(temp,tel[flag1[i]]); strcpy(tel[flag1[i]],tel[flag1[k]]); strcpy(tel[flag1[k]],temp); tem=flag2[i]; flag2[i]=flag2[k]; flag2[k]=tem; } for(i=0;i<h;i++) printf("%s %d\n",tel[flag1[i]],flag2[i]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator