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.h> #include<string.h> #include<stdlib.h> long a[100010]; int func_name(const void *a,const void *b) { if (*( long int*) a>*( long int* )b) return 1; if( *( long int*)a<*( long int*) b) return -1; return 0; } int main() { long i; long n,j,index=0; cin>>n; int have=0; for(i=0;i<n;i++){ long int num=0; //int judge=0; for( j=0;j<7;j++){ char temp; cin>>temp; switch(temp){ /* case 'Q': case 'Z': judge=1;break; */ case '0': num=num*10;break; case '1': num=num*10+1;break; case '2': case 'A': case 'B': case 'C': num=num*10+2;break; case '3': case 'D': case 'E': case 'F': num=num*10+3;break; case '4': case 'G': case 'H': case 'I': num=num*10+4;break; case '5': case 'J': case 'K': case 'L': num=num*10+5;break; case '6': case 'M': case 'N': case 'O': num=num*10+6;break; case '7': case 'P': case 'R': case 'S': num=num*10+7;break; case '8': case 'T': case 'U': case 'V': num=num*10+8;break; case '9': case 'W': case 'X': case 'Y': num=num*10+9;break; default: j--;break; } //switch }// for j //if(judge==1) continue; a[index++]=num; }//for i qsort(a,index,sizeof(a[0]),func_name); a[index]=-1; long max=1; int jud=0; for( i=0;i<index;i++) { if(a[i+1]==a[i]){max++;continue;} if(max==1)continue; long tempa=a[i]/10000,tempb=a[i]%10000; cout<<tempa/100;tempa=tempa%100; cout<<tempa/10;tempa=tempa%10; cout<<tempa<<'-'; cout<<tempb/1000;tempb=tempb%1000; cout<<tempb/100;tempb=tempb%100; cout<<tempb/10;tempb=tempb%10; cout<<tempb<<' '<<max<<endl; jud=1; max=1; } if(jud==0)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