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 <string> #include <memory.h> #include <cmath> #include <iomanip> using namespace std; int flag[100001]; int main() { int N,i,j,f=0; cin>>N; string x; memset(flag,0,sizeof(flag)); for(i=0;i<N;i++) { cin>>x; int k=1; for(j=x.size()-1;j>=0;j--) { if(x[j]>='A'&&x[j]<'P') { flag[i]+=k*((int)(x[j]-'A')/3+2); k=k*10; } else if(x[j]=='P') { flag[i]+=k*7; k=k*10; } else if(x[j]>='R'&&x[j]<='Y') { flag[i]+=k*((int)(x[j]-'Q')/3+7); k=k*10; } else if(x[j]>='0'&&x[j]<='9') { flag[i]+=k*((int)(x[j]-'0')); k=k*10; } // cout<<flag[i]<<endl; // system("PAUSE"); } } sort(flag,flag+N); int num,shu=flag[0]; cout<<endl; for(i=1,num=1;i<N;i++) { if(flag[i]==shu) num++; if(flag[i]!=shu||i==N-1) { if(num>1) { cout<<setw(3)<<setfill('0')<<right<<shu/10000<<'-'; cout<<setw(4)<<setfill('0')<<right<<(shu%10000)<<' '; cout<<num<<endl; f=1; } num=1; shu=flag[i]; } } if(f==0) cout<<"No duplicates."<<endl; system("PAUSE"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator