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 |
第一次做练习,Wrong,求大牛指点#include <iostream> #include <stdio.h> using namespace std; struct tel { char number [8]; int times; }; tel directory [100000]; int item; int duplicate; char to_int(char temp) { if (temp=='A'||temp=='B'||temp=='C') return '2'; if (temp=='D'||temp=='E'||temp=='F') return '3'; if (temp=='G'||temp=='H'||temp=='I') return '4'; if (temp=='K'||temp=='L'||temp=='J') return '5'; if (temp=='M'||temp=='N'||temp=='O') return '6'; if (temp=='P'||temp=='R'||temp=='S') return '7'; if (temp=='T'||temp=='U'||temp=='V') return '8'; if (temp=='W'||temp=='X'||temp=='Y') return '9'; else return temp; } int compare(char str1[],char str2[]) { for(int i=0;i<7;i++) { if(str1[i]<str2[i]) return 1; else if(str1[i]>str2[i]) return -1; } return 0; } void copy(char str1[], char str2[]) { for(int i=0;i<8;i++) { str1[i]=str2[i]; } } int mk_directory(int item) { char temp; int i=0; int tel_num=0; duplicate=0; char num; while(i<item) { char stemp[7]; int j=0; int k=0; for(j=0;j<20&&k<7;j++) { cin>>temp; if(temp!='-') { num=to_int(temp); stemp[k++]=num; } } stemp[8]='\0'; int t; for(t=0;t<tel_num;t++) { if(compare(directory[t].number,stemp)==0) { directory[t].times++; duplicate=1; break; } } if (t==tel_num) { for(t=tel_num;t>0;t--) { if(compare(directory[t-1].number,stemp)==-1) { copy(directory[t].number,directory[t-1].number); directory[t].times=directory[t-1].times; } else break; } copy(directory[t].number,stemp); directory[t].times=1; tel_num++; } i++; } return tel_num; } int main() { cin>>item; int tel_num=mk_directory(item); int i; int j; for(i=0;i<tel_num;i++) { for( j=0;j<3;j++) cout<<directory[i].number[j]; cout<<'-'; for( j=3;j<7;j++) cout<<directory[i].number[j]; cout<<' '<<directory[i].times<<endl; } if(!duplicate) cout<<"No duplicates."<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator