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 |
我觉的自己能省的都省了,怎么还是在tle呢?困惑……是循环太多了吗?#include <iostream.h> #include <string.h> #include <stdlib.h> #include <iomanip.h> int count[100000],tcount; int cmp ( const void *a ,const void *b ) { int *m = (int *)a, *n = (int *)b ; if ( *m > *n ) return 1; if ( *m < *n ) return -1; else return 0; } void main(){ int i,j,n,k,l,t,state=0; cin>>n; long int *tel=new long int [n]; char calln[400]; char teln[8]; for(i=0;i<n;i++){ cin>>calln; l=strlen(calln); t=0; for(k=0;k<l;k++){ if(calln[k]>='A'&&calln[k]<='Z'){ switch(calln[k]){ case'A':case'B':case'C': teln[t]='2';break; case'D':case'E':case'F': teln[t]='3';break; case'G':case'H':case'I': teln[t]='4';break; case'J':case'K':case'L': teln[t]='5';break; case'M':case'N':case'O': teln[t]='6';break; case'P':case'R':case'S': teln[t]='7';break; case'T':case'U':case'V': teln[t]='8';break; case'W':case'X':case'Y': teln[t]='9';break; } t++; } if(calln[k]>='0'&&calln[k]<='9'){ teln[t]=calln[k]; t++;} } teln[7]='\0'; tel[i]=atoi(teln); } qsort(tel,n,sizeof(long int),cmp); for(i=0;i<n;i++){ count[i]=1; if(tel[i]!=-1){ for(j=i+1;j<n;j++) if(tel[i]==tel[j]){ tel[j]=-1; count[i]++; } if(count[i]>1){ state=1; cout<<setfill('0')<<setw(3)<<tel[i]/10000<<"-"<<setw(4)<<tel[i]%10000 <<" "<<count[i]<<endl; } } } if(state==0) cout<<"No duplicates."<<endl; delete []tel; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator