提交总是超时,POJ1002
提交总是超时,不知道是哪里效率太低,高手帮忙分析下吧程序代码:
#include <stdio.h> #include <string.h> #define maxsize 100000 #define num_len 9 void Qsort(char a[][9],int l,int h); int main() { int size,i,flag=1; char ph_num[maxsize][num_len]; char map[] = {"22233344455566677778889999"}; char input[50]; scanf("%d",&size); for(i=0;i<size;i++) { int j=0,k; scanf("%s",input); for(k=0;input[k]!='\0';k++) { if(input[k]>='0' && input[k]<='9') ph_num[i][j++] = input[k]; else if(input[k]>='A' && input[k]<='Z') ph_num[i][j++] = map[input[k]-'A']; else continue; if(j==3) ph_num[i][j++] = '-'; } ph_num[i][j] = '\0'; } Qsort(ph_num,0,size-1); for(i=1;i<size;i++) if(strcmp(ph_num[i-1],ph_num[i]) == 0) break; if(i==size) { printf("No duplicates\n"); return 0; } for(i=0;i<size-1;i++) { if(strcmp(ph_num[i],ph_num[i+1]) == 0) flag++; else { if(flag > 1 ) printf("%s %d\n",ph_num[i],flag); flag = 1; } } if(flag > 1) printf("%s %d\n",ph_num[i],flag); return 0; } int partion(char a[][9],int low,int high) { char key[9]; strcpy(key,a[low]); while(low<high) { while(low<high && strcmp(a[high],key)>=0) --high; strcpy(a[low],a[high]); while(low<high && strcmp(a[low],key)<=0) ++low; strcpy(a[high],a[low]); } strcpy(a[low],key); return low; } void Qsort(char a[][9],int low,int high) { int keyloc; if(low<high) { keyloc = partion(a,low,high); Qsort(a,low,keyloc-1); Qsort(a,keyloc+1,high); } }
原题地址在这里 http://