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 |
这是怎么回事呀?先前我用冒泡排序,TLE,换用递归的快速排序后总 RUNTIME ERROR,请高手指教一下,多谢#include<stdio.h> #include<malloc.h> #include<conio.h> #include<stdlib.h> #include<math.h> int constnum[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,-1}; int compare(const void *a,const void *b) { return *((int *)a)-*((int *)b); } int partition(long int *tel,int start,int end) { int low,high; long int value; low=start; high=end; value=tel[low]; while(low<high) { while(low<high && tel[high]>=value) --high; tel[low]=tel[high]; while(low<high && tel[low]<=value) ++low; tel[high]=tel[low]; } tel[low]=value; return low; } void quick_sort(long int *tel,int start,int end) { int p; if(start<end) { p=partition(tel,start,end); quick_sort(tel,start,p-1); quick_sort(tel,p+1,end); } } void conv_code(int num) { int k; for(k=6;k>=0;k--) { if(k!=3) printf("%d",num/(int)pow(10,k)); else if(k==3) printf("-%d",num/(int)pow(10,k)); num=num%(int)pow(10,k); } } void print(long int *tel,int n) { int i,j,cal,sign; sign=0; i=0; while(i<n) { cal=1; while(tel[i]==tel[i+cal]) cal++; if(cal>1) { conv_code(tel[i]); printf(" %d",cal); printf("\n"); sign=1; } i=i+cal; } if(sign!=1) printf("No duplicates.\n"); } int main() { int i,j,k; int num; long int *telnum; char a[15]; scanf("%d",&num); telnum=(long int *)malloc(num*sizeof(long int)); for(i=0;i<num;i++) telnum[i]=0; for(i=0;i<num;i++) { scanf("%s",a); k=6; for(j=0;a[j]!='\0';j++) { if(a[j]>='A' && a[j]<='Z') { telnum[i]+=constnum[a[j]-'A']*(int)pow(10,k); k--; continue; } if(a[j]>='0' && a[j]<='9') { telnum[i]+=(a[j]-'0')*(int)pow(10,k); k--; continue; } } } //quick_sort(telnum,0,num-1); qsort(telnum,num,sizeof(int),compare); print(telnum,num); getch(); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator