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,最没有提示性的结果,搞不定了,大伙谁给看看#include <stdio.h> #include <stdlib.h> #define BUFSIZE 20 #define ERRNUM 10 struct list_item { int number; int count; }; struct list_item list_array[100000]; int list_add_number(int idx,int number); int list_sort(const void *a,const void *b); int list_print(int o_count); int main() { char in_buf[BUFSIZE]; int in_count,number,o_count=0; int i,j,k; scanf("%d",&in_count); // printf("%d\n",in_count); while(in_count>0) { scanf("%s",in_buf); --in_count; number=0;k=0; for(i=0;i<BUFSIZE;++i) { switch(in_buf[i]) { case 'A': case 'B': case 'C': case '2': j=2;break; case 'D': case 'E': case 'F': case '3': j=3;break; case 'G': case 'H': case 'I': case '4': j=4;break; case 'J': case 'K': case 'L': case '5': j=5;break; case 'M': case 'N': case 'O': case '6': j=6;break; case 'P': case 'R': case 'S': case '7': j=7;break; case 'T': case 'U': case 'V': case '8': j=8;break; case 'W': case 'X': case 'Y': case '9': j=9;break; case '1': j=1;break; case '0': j=0;break; case '-': j=ERRNUM;break; default: j=ERRNUM;break; } if(k<7) { if((j>=0)&&(j<ERRNUM)) { k++; number=number*10+j; } } else { k=0; break; } } // printf("%d\n",o_count); o_count+=list_add_number(o_count,number); // printf("%d\n",o_count); } // list_print(o_count); //排序,qsort qsort(list_array,o_count,sizeof(struct list_item),list_sort); list_print(o_count); //list_destroy(my_list_head); return 0; } int list_add_number(int idx,int number) { int i; int add_done=0; // printf("%d\n",number); for(i=0;i<idx;++i) { if(number==list_array[i].number) { (list_array[i].count)++; return 0; } } list_array[i].number=number; list_array[i].count=1; return 1; } int list_sort(const void *a,const void *b) { return (*(struct list_item *)a).number > (*(struct list_item *)b).number ? 1 : -1; } int list_print(int o_count) { int i,a,b; for(i=0;i<o_count;++i) { if(list_array[i].count<=1) continue; a=list_array[i].number / 10000; b=list_array[i].number % 10000; printf("%03d-%04d %d\n",a,b,list_array[i].count); } if(o_count==0) printf("No duplicates.\n"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator