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 |
救命啊!!!In Reply To:原来数组要开这么大啊!!! Posted by:xpwang at 2008-05-31 10:32:25 > 我也改成50了,可就不AC了,真太不爽了!!! #include <iostream> using namespace std; void unit(char *str) { int i=1; while(str[i]!='\0') { if(str[i]<60) { i++; //logic error:!! continue; } //logic error:!!! else if(str[i]>='A'&&str[i]<='C') str[i]='2'; else if(str[i]<='F') str[i]='3'; else if(str[i]<='I') str[i]='4'; else if(str[i]<='L') str[i]='5'; else if(str[i]<='O') str[i]='6'; else if(str[i]<='S') str[i]='7'; else if(str[i]<='V') str[i]='8'; else if(str[i]<='Y') str[i]='9'; i++; } } bool isSame(char *str1,char *str2) { bool f=true; int i=1,j=1; while(str1[i]!='\0'&&str2[j]!='\0') { if(str1[i]!='-'&&str2[j]!='-') { if(str1[i]!=str2[j]) f=false; i++,j++; } else if(str1[i]=='-'&&str2[j]!='-') { i++; } else if(str1[i]!='-'&&str2[j]=='-') { j++; } else { i++,j++; } } return f; } void out(char *str) { int c=0,i=1; while(str[i]!='\0') //logic error:!!! { if(c==3) { cout<<"-"; c++; //logic error:!! } if(str[i]!='-') { cout<<str[i]; c++; } i++; } } int isLarger(const void* stra,const void* strb) { int i=1,j=1,c=0, //logic error:i,j must be initialized. f=0; char *str1=*(char**)stra,*str2=*(char**)strb; while(str1[i]!='\0'&&str2[j]!='\0') { if(str1[i]!='-'&&str2[j]!='-') //logic error:!!!! { if(str1[i]!=str2[j]) { f=str1[i]-str2[j]; break; } else { i++; j++; } } else if(str1[i]=='-'&&str2[j]!='-') { i++; } else if(str1[i]!='-'&&str2[j]=='-') { j++; } else { i++,j++; } } return f; } int main() { int n,i; cin>>n; char **pstr=(char **)malloc(sizeof(char*)*n); memset(pstr,'\0',sizeof(char*)*n); for(i=0;i<n;i++) { pstr[i]=(char *)malloc(sizeof(char)*50); memset(pstr[i],'\0',sizeof(char)*50); pstr[i][0]=1; cin>>pstr[i]+1; //logic error:begin from pstr[i]+1 } //process for(i=0;i<n;i++) { unit(pstr[i]); } //sort qsort(pstr,n,sizeof(char*),isLarger); //count int j; for(i=0;i<n;i=j) { j=i+1; while(j<n&&isSame(pstr[i],pstr[j]))//logic error:j<n!!! { pstr[i][0]++; j++; } } //out int f=0; for(i=0;i<n;i++) { if(pstr[i][0]>1) { out(pstr[i]); cout<<" "<<(int)pstr[i][0]<<endl; f++; } } if(!f) 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