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 |
我用了快速排序,用了转换数字。本地运行完全正确,且快,为什么就超时了呢?各路大哥帮小弟看看,小弟感激不尽!!急!!!#include<iostream> #include<cmath> #include<iomanip> using namespace std; int swap1(char a) { switch(a) { case 'A': case 'B': case 'C': case '2': return 2; case 'D': case 'E': case 'F': case '3': return 3; case 'H': case 'I': case 'G': case '4': return 4; case 'J': case 'K': case 'L': case '5': return 5; case 'M': case 'N': case 'O': case '6': return 6; case 'P': case 'R': case 'S': case '7': return 7; case 'T': case 'U': case 'V': case '8': return 8; case 'W': case 'X': case 'Y': case '9': return 9; case '0': return 0; case '1': return 1; } } int swap2(char s[]) { int i=0,j=6,sum=0; for(i=0;i<=strlen(s)-1;i++) if(s[i]!='-') { sum+=swap1(s[i])*pow(10,j); j--; } return sum; } void kuaipai(int a[],int m,int n) { if(m>=n) return ; int p=m,q=n; int temp=a[m]; while(p<q) { while(p<q&&temp<=a[q]) q--; if(p<q) a[p]=a[q]; while(p<q&&a[p]<=temp) p++; if(p<q) a[q]=a[p]; } a[p]=temp; kuaipai(a,m,p-1); kuaipai(a,p+1,n); return ; } int main() { int ss[100001]; bool hh=false; char b[100]; int n,i,j; cin>>n; for(i=1;i<=n;i++) { cin>>b; ss[i]=swap2(b); } kuaipai(ss,1,n); for(i=1;i<=n;i++) { j=1; while(i<n) { if(ss[i]==ss[i+1]) { j++; i++; } else break; } if(j!=1) { hh=true; cout<<setw(3)<<setfill('0')<<ss[i]/10000<<'-'<<setw(4)<<setfill('0')<<ss[i]%10000<<" "<<j<<endl; } } if(hh==false) 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