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 |
虽然这个问题很郁闷,老是RE,各位有心的帮我来看看吧. 用的c和qsort,100000的数组分在堆上.#include <stdio.h> #include <string.h> #include <stdlib.h> char* dic[]={"ABC","DEF","GHI","JKL","MNO","PRS","TUV","WXY"}; int diclen=8; int string_compare(const void * l,const void *r) { return strcmp((char*)l,(char*)r); } char convert(char c) { int i=0; if(c=='-') return 0; if(c>='A'&&c<='Z') { for(;i<diclen;i++) { if(strchr(dic[i],c)) return 50+i; } } return c; } int isThesameArray(char* l,char* r) { int i=0; for(;i<7;i++) if(l[i]!=r[i]) return 0; return 1; } int main(void) { int num,i,j,k,addr=0,noanswer; int count[MAX]; char once[255]; char temp; char (*output)[7]; scanf("%d",&num); output=(char(*)[7])malloc(num*7*sizeof(char)); //将输入的数据换成7位的标准格式 for(i=0;i<num;i++) count[i]=1; for(i=0;i<num;i++) { scanf("%s",once); for(j=0;j<strlen(once);j++) { temp=convert(once[j]); if(temp!=0) { output[i][addr]=temp; addr++; } } addr=0; } qsort(output,num,7*sizeof(char),string_compare); //判断重复次数并且输出 for(i=0;i<num;i++) { if(count[i]!=-1) for(j=i+1;j<num;j++) { if(isThesameArray(output[i],output[j])) { count[i]++; count[j]=-1; } } } noanswer=1; for(i=0;i<num;i++) { if(count[i]>1) { for(j=0;j<7;j++) { if(j==3) printf("-%c",output[i][j]); else printf("%c",output[i][j]); } printf(" %d\n",count[i]); } noanswer=0; } if(noanswer==1) printf("No duplicates."); free(output); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator