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 |
实在找不出错误了。进来一看,和某些人的代码几乎一样, 最后一个重复的考虑了, 然后就是前面是0的也注意了。 到底哪里错了呢〉?实在找不出了。 #include <iostream> #include <algorithm> #include <iomanip> using namespace std; int main() { int n; cin>>n; int* a=new int[n]; int i,j; char arr[30]; for(i=0;i<n;i++) { int x=0; memset(arr,'\0',sizeof(char)*30); cin>>arr; for(j=0;j<strlen(arr);j++) { char c=arr[j]; if('-'==c) continue; else if(c>='0'&&c<='9') x=x*10+c+0-'0'; else if(c>='A'&&c<='Z') { switch(c) { case 'A':case 'B':case 'C': x=x*10+2; break; case 'D': case 'E': case 'F': x=x*10+3; break; case 'G': case 'H': case 'I': x=x*10+4; break; case 'J': case 'K': case 'L': x=x*10+5; break; case 'M': case 'N': case 'O': x=x*10+6; break; case 'P': case 'R': case 'S': x=x*10+7; break; case 'T': case 'U': case 'V': x=x*10+8; break; case 'W': case 'X': case 'Y': x=x*10+9; break; } } } a[i]=x; } sort(a,a+n); int count=1; bool more_than_one=false; for(i=0;i<n-1;i++) { if(a[i]==a[i+1]) count++; else { if(count>1) cout<<setfill('0')<<setw(3)<<a[i]/10000<<'-'<<setfill('0')<<setw(4)<<a[i]%10000<<" "<<count<<endl; count=1; more_than_one=true; } } if(count>1)//the max one has duplicates { cout<<setfill('0')<<setw(3)<<a[n-1]/10000<<'-'<<setfill('0')<<setw(4)<<a[n-1]%10000<<" "<<count<<endl; more_than_one=true; } if(!more_than_one) cout<<"No duplicates."<<endl; delete[] a; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator