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 |
请各位看看哪错了,先谢谢了#include<stdio.h> #include<string.h> #include<stdlib.h> typedef struct { char b[8]; int n; }ad; ad z[100010]; int cmp(const void *p1,const void *p2) { ad *m,*n; m=(ad *)p1; n=(ad *)p2; return strcmp(m->b,n->b); } char conv(char c) { if(c=='A'||c=='B'||c=='C') return '2'; if(c=='D'||c=='E'||c=='F') return '3'; if(c=='G'||c=='H'||c=='I') return '4'; if(c=='J'||c=='K'||c=='L') return '5'; if(c=='M'||c=='N'||c=='O') return '6'; if(c=='P'||c=='R'||c=='S') return '7'; if(c=='T'||c=='U'||c=='V') return '8'; if(c=='W'||c=='X'||c=='Y') return '9'; } int main() { int i,j,k,l,p,flag,m,t,s; char tem[50],a[1000]; while (scanf("%d",&m)==1) { l=0;flag=0; for(i=0;i<m;i++) { scanf("%s",a); t=strlen(a); k=0; for(j=0;j<t;j++) { if((a[j]>='0')&&(a[j]<='9')) tem[k++]=a[j]; else if((a[j]>='A')&&(a[j]<'Z')) tem[k++]=conv(a[j]); } tem[k]='\0'; for(p=0;p<l;p++) if(strcmp(tem,z[p].b)==0) { z[p].n++; break; } if(p==l) { strcpy(z[l].b,tem); z[l].n=1; l++; } } s=0; for(i=0;i<l;i++) { if(z[i].n>1) z[s++]=z[i]; } qsort(z,s,sizeof(z[0]),cmp); for(i=0;i<s;i++) { for(j=0;j<8;j++) { printf("%c",z[i].b[j]); if(j==2) printf("-"); } printf(" %d\n",z[i].n); flag=1; } if(flag==0) printf("No duplicates.\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator