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 |
哪位好心人士帮我看看程序咯!改了半天还是错,步骤有些标了说明```我快要抓狂了# include <iostream.h> # include <string.h> # include <stdlib.h> # include <iomanip.h> char change[27]={"22233344455566677778889999"}; int compare(const void* a, const void* b); void main() { int n,N,M=0,len; char array1[100][16],array2[100][9]; bool turn=false; cin>>N; for(int i=0;i<N;i++){ //将号码全部转换为数字串 cin>>array1[i]; len=strlen(array1[i]); M=0; for(int m=0;m<len;m++){ if(array1[i][m]>='A' && array1[i][m]<='Z'){ array2[i][M]=change[array1[i][m]-'A']; //?为什么赋值不成功呢??? M++; continue; } if(array1[i][m]>='0' && array1[i][m]<='9'){ array2[i][M]=array1[i][m]; M++; } } } qsort((void*)array2,N,sizeof(array2[0]),compare); //将电话号码排序 char b[9]; strcpy(b,array2[0]); for(int j=1;j<N;j++){ //查找相同的号码 if(strcmp(array2[j],b)==0) {n++;turn=true; continue;} if(n>1){ for(int k=0;b[k]!='\0';k++){ if(k==3) cout<<"-"<<b[k]; else cout<<b[k]; } cout<<setfill(' ')<<setw(2)<<n<<endl; //输出 n=1;strcpy(b,array2[j]); } } if(!turn) cout<<"No duplicates."<<endl; //找不到时的输出 } int compare(const void* a,const void* b){ return strcmp(*(char **)a,*(char **)b); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator