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 |
help!! 一直runtime error,牛人帮下忙呀!#include<math.h> #include<stdio.h> void treat(char *in,long *data,int n) {int i,count=0; long sum=0; for(i=0;i<=14;i++) { if(in[i]=='-')continue; else if(in[i]>='0'&&in[i]<='9') {count++; sum+=(in[i]-'0')*pow(10,7-count); } else if(in[i]>='A'&&in[i]<='C') { count++; sum+=2*pow(10,7-count); } else if(in[i]>='D'&&in[i]<='F') { count++; sum+=3*pow(10,7-count); } else if(in[i]>='F'&&in[i]<='I') { count++; sum+=4*pow(10,7-count); } else if(in[i]>='J'&&in[i]<='L') { count++; sum+=5*pow(10,7-count); } else if(in[i]>='M'&&in[i]<='O') { count++; sum+=6*pow(10,7-count); } else if(in[i]>='R'&&in[i]<='S'||in[i]=='P') { count++; sum+=7*pow(10,7-count); } else if(in[i]>='T'&&in[i]<='V') { count++; sum+=8*pow(10,7-count); } else if(in[i]>='W'&&in[i]<'Z') { count++; sum+=9*pow(10,7-count); } if(count==7)break; } data[n]=sum; } int partition(long *data,int a,int b) {int low=a,high=b; long temp=data[low],temp2; while(low<high) {while(low<high&&data[high]>=temp)high--; data[low]=data[high]; while(low<high&&data[low]<=temp)low++; data[high]=data[low]; } data[low]=temp; return low; } void quicksort(long *data,int low,int high) {int temp; if(low<high) {temp=partition(data,low,high); quicksort(data,low,temp-1); quicksort(data,temp+1,high); } } main() {char in[15]; long n,count=-1,i;long *data; scanf("%d",&n); data=(long *)malloc((n+1)*sizeof(long)); while(count<n-1) {count++; scanf("%s",in); treat(in,data,count); } quicksort(data,0,n-1); count=0; for(i=1;i<n;i++) { if(data[i]==data[i-1])count++; else if(data[i]!=data[i-1]) { if(count>0) {int j;char s[7]; for(j=0;j<=6;j++) s[j]=data[i-1]%(int)pow(10,7-j)/pow(10,6-j); for(j=0;j<=2;j++)printf("%d",s[j]); printf("-"); for(j=3;j<=6;j++)printf("%d",s[j]); printf(" %d\n",count+1); } count=0; } } free(data); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator