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 |
数组开到20 就WA了,这是A过的!供借鉴!#include<iostream> #include<cstring> #include<stdlib.h> #include<string.h> #include<memory.h> using namespace std; struct Telephone_number { char s[100]; } my[100005]; int cmp(const void *a , const void *b) { return strcmp ((*(Telephone_number *)a).s , (*(Telephone_number *)b).s) ; } int main() { int n; char ch[]="22233344455566677778889999"; while(cin>>n) { for(int i=0;i<n;i++) { cin>>my[i].s; } char s1[100]; for(int i=0;i<n;i++) { int k=0; int len=strlen(my[i].s); for(int j=0;j<len;j++) { if(my[i].s[j]>='A'&&my[i].s[j]<='Z') { s1[k]=ch[my[i].s[j]-'A']; k++; } else if(my[i].s[j]>='0'&&my[i].s[j]<='9') { s1[k]=my[i].s[j]; k++; } else { continue; } s1[7]='\0'; } strcpy(my[i].s,s1); } qsort(my,n,sizeof(my[0]),cmp); int flag=0; int sum=1; for(int i=0;i<n;i++) { if(strcmp(my[i].s,my[i+1].s)==0) { sum++; flag=1; } else { if(sum>1) { for(int k=0;k<7;k++) { if(k==3) { cout<<"-"; } cout<<my[i].s[k]; } cout<<" "<<sum<<endl; } sum=1; continue; } } if(flag!=1) { cout<<"No duplicates."<<endl; } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator