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<stdio.h> struct T{ char ch[8]; int t; }; char match(char c){ switch(c){ case 'A': case 'B': case 'C': return '2'; case 'D': case 'E': case 'F': return '3'; case 'G': case 'H': case 'I': return '4'; case 'J': case 'K': case 'L': return '5'; case 'M': case 'N': case 'O': return '6'; case 'P': case 'R': case 'S': return '7'; case 'T': case 'U': case 'V': return '8'; case 'W': case 'X': case 'Y': return '9'; default: return c; } } int main(){ int count,len,i=0,j,k; T str[200000]; char temp[50],tmpstr[8],pstr[8]; scanf("%d",&count); while(count>0){ cin>>temp; len = strlen(temp); for(j=0,k=0;j<len;j++) if(temp[j]!='-') tmpstr[k++]=match(temp[j]); if(i==0){ for(k=0;k<9;k++) str[0].ch[k]=tmpstr[k]; str[0].t=1; i++; count--; continue; } for(j=0;j<i;j++){ if(strcmp(tmpstr,str[j].ch)==0){ str[j].t++; count--; break; } else if(strcmp(tmpstr,str[j].ch)<0){ for(k=i-1;k>=j;k--) str[k+1]=str[k]; for(k=0;k<9;k++) str[j].ch[k]=tmpstr[k]; str[j].t=1; i++; count--; //cout<<i<<endl; //cout<<str[j].ch<<" "<<str[j].t<<endl; break; } } if(j==i){ for(k=0;k<9;k++) str[i].ch[k]=tmpstr[k]; str[i].t=1; i++; count--; } } bool flag = true; for(j=0;j<i;j++){ if(str[j].t>1){ flag = false; for(k=0;k<8;k++){ if(k==3) cout<<'-'; cout<<str[j].ch[k]; } cout<<" "<<str[j].t<<endl; } } if(flag) 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