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> struct node { int name;int numb; }pres[10001]; int cmp(const void *a,const void *b) { return (*(struct node*)a).name-(*(struct node*)b).name; } int transform(char a) { if(a=='A'||a=='B'||a=='C') { return 2; } if(a=='D'||a=='E'||a=='F') { return 3; } if(a=='G'||a=='H'||a=='I') { return 4; } if(a=='J'||a=='K'||a=='L') { return 5; } if(a=='M'||a=='N'||a=='O') { return 6; } if(a=='P'||a=='R'||a=='S') { return 7; } if(a=='T'||a=='U'||a=='V') { return 8; } if(a=='W'||a=='X'||a=='Y') { return 9; } if(a=='-'||a=='Q'||a=='Z') { return -1; } if(a>='0'&&a<='9') { int p=a-48; return p; } } int main() { int n;scanf("%d",&n); for(int i=0;i<n;i++) { char a[300]; scanf("%s",a); int ilen=strlen(a); for(int j=0;j<ilen;j++) { int num=transform(a[j]); if(num!=-1) { pres[i].name=pres[i].name*10+num; } } } qsort(pres,n,sizeof(pres[0]),cmp);int flag=0; for(int i=0;i<n;i++) { if(pres[i].name==pres[i+1].name) { pres[i].name=-1;pres[i+1].numb=pres[i].numb+1;pres[i].numb=0;flag++; } } for(int i=0;i<n;i++) { if(pres[i].numb>0) { printf("%03d-%04d %d\n",pres[i].name/100,pres[i].name%100,pres[i].numb+1); } } if(flag==0) { printf("No duplicates. "); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator