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> typedef struct{ int s1[7]; int num1; }test1; test1 test[300]; test1 temp; int qsort(int j,int k) { if(test[j].s1[k]>test[j+1].s1[k]) { return 1; } else if(test[j].s1[k]==test[j+1].s1[k]) { if(qsort(j,k+1)==1) return 1; } return 0; } int main() { int s[300][7]; int num[300]; int n,i,j,k,m=0; char c; scanf("%d",&n); c=getchar(); for(i=0;i<n;i++) { j=0; c=getchar(); while(c!='\n') { switch (c) { case 'A': case 'B': case 'C': case '2': s[i][j]=2;j++;break; case 'D': case 'E': case 'F': case '3': s[i][j]=3;j++;break; case 'G': case 'H': case 'I': case '4': s[i][j]=4;j++;break; case 'J': case 'K': case 'L': case '5': s[i][j]=5;j++;break; case 'M': case 'N': case 'O': case '6': s[i][j]=6;j++;break; case 'P': case 'R': case 'S': case '7': s[i][j]=7;j++;break; case 'T': case 'U': case 'V': case '8': s[i][j]=8;j++;break; case 'W': case 'X': case 'Y': case '9': s[i][j]=9;j++;break; case '0': s[i][j]=0;j++;break; case '1': s[i][j]=1;j++;break; } c=getchar(); } } for(i=0;i<n;i++) { num[i]=1; } for(i=0;i<n;i++) { for(k=i+1;k<n;k++) { int l=0; for(j=0;j<7;j++) { if(s[i][j]==s[k][j]) { l++; if(l==6) { num[i]=1; num[k]=num[k]+1; } } } } } for(i=0;i<n;i++) { if(num[i]!=1) { for(j=0;j<7;j++) { test[m].s1[j]=s[i][j]; } test[m].num1=num[i]; m++; } } for(i=0;i<m;i++) { for(j=0;j<m-i-1;j++) { if(qsort(j,0)==1) { temp=test[j]; test[j]=test[j+1]; test[j+1]=temp; } } } if(m==0) { printf("No duplicates.\n"); } for(i=0;i<m;i++) { for(j=0;j<3;j++) { printf("%d",test[i].s1[j]); } printf("-"); for(j=3;j<7;j++) { printf("%d",test[i].s1[j]); } printf(" %d\n",test[i].num1); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator