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 |
Runtime error.高手帮看看#include <iostream.h> #include <algorithm> #include <iomanip.h> #include <stdlib.h> const int LONG=15,SHORT=7; bool compare(int a,int b) { return a<b; } void main() { int num,i,j,count,flag=1; char list[90],teml[LONG],tems[SHORT]; for(i='0';i<='9';i++) list[i]=i; for(i='A';i<='O';i++) list[i]=(i-'A')/3+'2'; for(i='Q';i<='Y';i++) list[i]=(i-'Q')/3+'7'; list['P']=list['Q']; cin>>num; int * tel=new int[num]; for(i=0;i<num;i++) { char *ori=tems; cin>>teml; for(int j=0;teml[j];j++) if(teml[j]!=45) *ori++=list[teml[j]]; //'-'=45 tel[i]=atoi(tems); } std::sort(tel,tel+num,compare); for(i=0;i<num;) //output. follow a teacher's example; { count=1; for(j=i+1;j<num&&tel[j]==tel[i];j++) count++; if(count>1) { flag=0; cout<<setfill('0')<<setw(3)<<tel[i]/10000<<"-"<<setfill('0')<<setw(4)<<tel[i]%10000<<" "<<count<<endl; } i=j; } if(flag) cout<<"No duplicates."<<endl; delete[]tel; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator