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!测试了几乎所有大家给的数据,也仔细看过代码,么有发现问题,提交总是WA.求教高人解答! 附代码: #include <iostream> #include <string.h> #include <algorithm> #define Max 100000 using namespace std; typedef struct Tel { char Num[8]; }; struct Tel telNum[Max]; bool compare(struct Tel &a,struct Tel &b) { if(strcmp(a.Num,b.Num)<0) { return true; } else { return false; } } int main() { memset(telNum,0,sizeof(telNum)); int i,j; int sum,n=0; int temp1=0,temp2=0; int total; cin>>sum for(j=0;j<sum;j++) { for(i=0;i<7;i++) { cin>>telNum[j].Num[i]; if(telNum[j].Num[i]=='-') { i--; } else if((telNum[j].Num[i]=='A')||(telNum[j].Num[i]=='B')||(telNum[j].Num[i]=='B')||(telNum[j].Num[i]=='2')) { telNum[j].Num[i]='2'; } else if((telNum[j].Num[i]=='D')||(telNum[j].Num[i]=='E')||(telNum[j].Num[i]=='F')||(telNum[j].Num[i]=='3')) { telNum[j].Num[i]='3'; } else if((telNum[j].Num[i]=='G')||(telNum[j].Num[i]=='H')||(telNum[j].Num[i]=='I')||(telNum[j].Num[i]=='4')) { telNum[j].Num[i]='4'; } else if((telNum[j].Num[i]=='J')||(telNum[j].Num[i]=='K')||(telNum[j].Num[i]=='L')||(telNum[j].Num[i]=='5')) { telNum[j].Num[i]='5'; } else if((telNum[j].Num[i]=='M')||(telNum[j].Num[i]=='N')||(telNum[j].Num[i]=='O')||(telNum[j].Num[i]=='6')) { telNum[j].Num[i]='6'; } else if((telNum[j].Num[i]=='P')||(telNum[j].Num[i]=='R')||(telNum[j].Num[i]=='S')||(telNum[j].Num[i]=='7')) { telNum[j].Num[i]='7'; } else if((telNum[j].Num[i]=='T')||(telNum[j].Num[i]=='U')||(telNum[j].Num[i]=='V')||(telNum[j].Num[i]=='8')) { telNum[j].Num[i]='8'; } else if((telNum[j].Num[i]=='W')||(telNum[j].Num[i]=='X')||(telNum[j].Num[i]=='Y')||(telNum[j].Num[i]=='9')) { telNum[j].Num[i]='9'; } } } sort(telNum,telNum+sum,compare); for(j=0;j<sum-1;j++) { if((strcmp(telNum[j].Num,telNum[j+1].Num)==0)&&(j!=sum-2)) { temp2++; } else if((strcmp(telNum[j].Num,telNum[j+1].Num)==0)&&(j==sum-2)) { total=temp2-temp1+2; for(i=0;i<3;i++) { cout<<telNum[j].Num[i]; } cout<<'-'; for(i=3;i<8;i++) { cout<<telNum[j].Num[i]; } cout<<" "<<total<<endl; n++; } else { total=temp2-temp1+1; temp1=j; temp2=temp1; if(total!=1) { for(i=0;i<3;i++) { cout<<telNum[j].Num[i]; } cout<<'-'; for(i=3;i<8;i++) { cout<<telNum[j].Num[i]; } cout<<" "<<total<<endl; n++; } } } if(n==0) { 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