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 <iostream.h> #include <string.h> #include <stdlib.h> #include <stdio.h> char *standardForm(char *calln); void main(){ int i,j,n,k,l,state=0,tcount,count[100000]={0}; cin>>n; int (*tel)[1]; char tele[100]; tel=new int [n][1]; int temp; count[0]=1; for(i=0;i<n;i++){ cin>>tele; strcpy(tele,standardForm(tele)); tel[i][0]=atoi(tele); for(j=0;j<i;j++) if(tel[i][0]==tel[j][0]){ count[j]++;i--;n--; break; } if(i==0) continue; if(j==i) count[j]++; } for(i=0;i<n;i++){ k=i; for(j=i+1;j<n;j++) if(tel[k][0]>tel[j][0]) k=j; temp=tel[i][0]; tel[i][0]=tel[k][0]; tel[k][0]=temp; tcount=count[i]; count[i]=count[k]; count[k]=tcount; } for(i=0;i<n;i++){ if(count[i]!=1){ sprintf(tele,"%d",tel[i][0]); l=strlen(tele); j=0; if(l<7) for(;j<(7-l);j++){ if(j==3) cout<<"-"; cout<<'0'; } for(k=0;k<l;k++) { if((k+j)==3) cout<<"-"; cout<<tele[k]; } cout<<" "<<count[i]<<endl; state=1; } } if(state==0) cout<<"No duplicates."<<endl; delete []tel; } char *standardForm(char * calln){ static char teln[8]; int l=strlen(calln),i=0; for(int k=0;k<l;k++){ if(calln[k]>='A'&&calln[k]<='Z'){ switch(calln[k]){ case'A':case'B':case'C': teln[i]='2';break; case'D':case'E':case'F': teln[i]='3';break; case'G':case'H':case'I': teln[i]='4';break; case'J':case'K':case'L': teln[i]='5';break; case'M':case'N':case'O': teln[i]='6';break; case'P':case'R':case'S': teln[i]='7';break; case'T':case'U':case'V': teln[i]='8';break; case'W':case'X':case'Y': teln[i]='9';break; } i++; } if(calln[k]=='-') continue; if(calln[k]>='0'&&calln[k]<='9'){ teln[i]=calln[k]; i++;} } teln[7]='\0'; return teln; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator