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 |
大牛们救命。。一直WA!!!!#include<stdio.h> #include<string.h> typedef struct number{ int temp; int times; }number; int char_change(char c) { if (c=='-'||c=='Q'&&c=='Z') return 10 ; if(c>='A'&&c<='C') return 2; if(c>='D' && c<='F') return 3; if(c>='G'&&c<='I') return 4; if(c>='J' && c<='L') return 5; if(c>='M' && c<='O') return 6; if(c=='P'||c=='R'||c=='S') return 7; if(c=='T'||c=='U'||c=='V') return 8; if(c=='W'||c=='X'||c=='Y') return 9; return (c-'0'); } int string_change(char a[]){ int i=0;/*注意初始化*/ int sum=0;/*注意初始化*/ int temp; while (a[i]!='\0') { temp=char_change(a[i]); if (temp==10) ; else sum=sum*10+temp; i++; } return sum; } void BubSort(number r[],int n) { int i,j; number t; int flag;/*flag=0 means no sorting;otherwise sorting */ for(i=n-1;i>0;i--) { flag=1; for(j=0;j<i;j++) if(r[j].temp>r[j+1].temp) { t.temp=r[j+1].temp; t.times=r[j+1].times; r[j+1].temp=r[j].temp; r[j+1].times=r[j].times; r[j].temp=t.temp; r[j].times=t.times; flag=0; } if(flag) break;/* 没有了排序就可以认为是可以跳出的!*/ } } int main(){ number temp[10000]={NULL}; char a[1000]={NULL}; int ptr_temp=0,count=0; /*数组的指针和最大个数*/ int sum=0; int Size; scanf("%d",&Size); while (Size--) { scanf("%s",a); sum=string_change(a); int flag=0; for (int i=0;i<count;i++) { if (temp[i].temp==sum) { temp[i].times++; flag=1; break; } } if (flag==0) { temp[count].temp=sum; temp[count].times++; count++; } } BubSort(temp,count); int flag=0; for (int i=0;i<count;i++) { if (temp[i].times==1); else{ printf("%d-%d %d\n",temp[i].temp/10000,temp[i].temp%10000,temp[i].times); flag=1; } } if (flag==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