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<stdlib.h> #include<string.h> int comp(const void *p, const void *q) { return (*(int *)p - *(int *)q); } int map[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,9}; main() { int num,i,j,p,q,count,duplicates; char str1[50]; int str2[50]; scanf("%d",&num); for(j=0;j<=num-1;j++) { str2[j]=0; scanf("%s",str1); for(i=0,p=0;str1[i];i++) { if(str1[i]!='-') { if(str1[i]>='A') str2[j]=str2[j]*10+map[str1[i]-'A']; else str2[j]=str2[j]*10+str1[i]-'0'; p++; } } //for } //排序 qsort(str2,j,sizeof(str2[0]),comp); count=0; duplicates=0; for(i=0;i<=j-1;i++) { if(str2[i]==str2[i-1]) count++; else{ if(count>0) { printf("%d-%d %d",str2[i-1]/10000,str2[i-1]%10000,count+1); printf("\n"); duplicates=1; } count=0; } } if(duplicates==0) printf("No duplicates.\n"); //system("PAUSE"); } 看起来很短了!!! Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator