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> #include<time.h> char* convert(char* ax,char* as){ int length=strlen(ax); int i=0,j=0; as[3]='-'; for(;*(ax+i)!='\0';i++) { if(j==3) j++; if(ax[i]=='-') {continue;} if(ax[i]>='0'&&ax[i]<='9') {as[j++]=ax[i];continue;} if(ax[i]<=67) {as[j++]='2';continue;} if(ax[i]<=70) {as[j++]='3';continue;} if(ax[i]<=73) {as[j++]='4';continue;} if(ax[i]<='L'){as[j++]='5';continue;} if(ax[i]<='O'){as[j++]='6';continue;} if(ax[i]<='S'){as[j++]='7';continue;} if(ax[i]<='V'){as[j++]='8';continue;} if(ax[i]<='Y'){as[j++]='9';continue;} } *(as+j)='\0'; return as; } void sort(char** ass,int size) { int i,j; char* temp; for(i=1;i<size;i++){ temp = ass[i]; j=i-1; while(j>=0&&strcmp(ass[j],temp)>0){ ass[j+1]=ass[j]; ass[j]=temp; j--; } } } int main(void) { long caseNum; long i=0; int count=1; char **arr,**ass; scanf("%ld",&caseNum); //初始化指针数组 arr = (char**)malloc(sizeof(char*)*caseNum); ass = (char**)malloc(sizeof(char*)*caseNum); for(;i<caseNum;i++){ arr[i] = (char*)malloc(sizeof(char)*15); ass[i] = (char*)malloc(sizeof(char)*8); scanf("%s",arr[i]); convert(arr[i],ass[i]); } sort(ass,caseNum); for(i=0;i<caseNum-1;i++){ if(strcmp(ass[i],ass[i+1])==0){ count++;continue; }else{ if(count>1){ printf("%s %d\n",ass[i],count); count=1; } continue; } } return EXIT_SUCCESS; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator