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 |
我发现自己给大家严重拖后腿了,试了好久,终于可以了最开始,还想到用二维数组存储,竟然不知道转化为整型变量,感觉自己真是弱爆了。。。 <code> #include<stdio.h> #include<string.h> #include<algorithm> #define MAXLEN 100000 using namespace std; int phone[MAXLEN]; int counter[MAXLEN]; int convert(char str[]) { int num=0; int i=0; while(str[i]!='\0') { switch(str[i]) { case '0':num=num*10;break; case '1':num=num*10+str[i]-'0';break; case '2':case 'A':case 'B':case 'C':num=num*10+2;break; case '3':case 'D':case 'E':case 'F':num=num*10+3;break; case '4':case 'G':case 'H':case 'I':num=num*10+4;break; case '5':case 'J':case 'K':case 'L':num=num*10+5;break; case '6':case 'M':case 'N':case 'O':num=num*10+6;break; case '7':case 'P':case 'R':case 'S':num=num*10+7;break; case '8':case 'T':case 'U':case 'V':num=num*10+8;break; case '9':case 'W':case 'X':case 'Y':num=num*10+9;break; } i++; } return num; } int main() { int n,i,j,num; int pre,sub; int flag=0; char str[300]; memset(phone,0,sizeof(phone)); memset(counter,0,sizeof(counter)); counter[0]=1; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%s",str); num=convert(str); phone[i]=num; } sort(phone,phone+n); for(i=1,j=0;i<n;i++) { if(phone[i]==phone[j]) { counter[j]++; }else { phone[++j]=phone[i]; counter[j]++; } } for(i=0;i<=j;i++) { if(counter[i]>1) { flag=1; pre=phone[i]/10000; sub=phone[i]%10000; printf("%03d-%04d %d\n",pre,sub,counter[i]); } } if(!flag) printf("No duplicates.\n"); return 0; } </code> Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator