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 |
郁闷啊~~~老runtime error~~~~~谁能帮忙看看怎么回事啊~~谢谢~~!#include <stdio.h> #include <string.h> void clear(char *p); void sort(char (*p)[16],int n); void cmp(char (*p)[16],int &n); void print(char (*p)[16],int n); int main() { int n; char a[1000][16]; scanf("%d",&n); for(int i = 0;i<n;i++) { scanf("%s",a[i]); clear(a[i]); } sort(a,n); cmp(a,n); print(a,n); return 0; } void clear(char *p) { for(int i=0;*(p+i)!=0;i++) { switch(p[i]) { case 'A': case 'B': case 'C':p[i]='2';break; case 'D': case 'E': case 'F':p[i]='3';break; case 'G': case 'H': case 'I':p[i]='4';break; case 'J': case 'K': case 'L':p[i]='5';break; case 'M': case 'N': case 'O':p[i]='6';break; case 'P': case 'R': case 'S':p[i]='7';break; case 'T': case 'U': case 'V':p[i]='8';break; case 'W': case 'X': case 'Y':p[i]='9';break; case '-': { for(int j=i;*(p+j)!=0;j++) { *(p+j)=*(p+j+1); } i--; }break; default:; } } for(int j=8;j>3;j--) { p[j]=p[j-1]; } p[3]='-'; } void sort(char (*p)[16],int n) { int i,j; for(i = 0;i < n;i++) { for(j = n-1;j > i;j--) { if(strcmpi(*(p+j-1),*(p+j))>0) { char temp[16]; strcpy(temp,*(p+j)); strcpy(*(p+j),*(p+j-1)); strcpy(*(p+j-1),temp); } } } } void cmp(char (*p)[16],int &n) { int i,j,k,r,c=0; for(i=0;i<n;i++) { for(j=i+1;!strcmpi(p[i],p[j])&&j<n;j++) c++; p[i][8]=32; p[i][9]=c+49; p[i][10]=0; if(c!=0) { for(r=i+1,k=j;k<n;k++) { strcpy(p[r],p[k]); r++; } n-=c; } c=0; } } void print(char (*p)[16],int n) { int i; for(i=0;i<n;i++) { if(p[i][9]>'1') printf("%s\n",*(p+i)); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator