| ||||||||||
| 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 | |||||||||
求帮助。。1002我写了5份代码了,但每一次都有不同的问题。
觉得这次应该没事了,可是却TLE了。
我算了下时间复杂度,只有 nlogn 可是为什么会超时呢?
求大牛们帮忙看看哈。
#include<string>
#include<cctype>
#include<cstring>
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
string teleNum[100003];
string str,temp;
char tmp[200];
bool jug;
int k,n,total,ct=0;
scanf("%d",&k);
while(k--){
str="";
scanf("%s",&tmp);
n=strlen(tmp);
for(int i=0;i<n;i++){
if(isdigit(tmp[i])) str+=tmp[i];
else if(isalpha(tmp[i])){
switch(tmp[i]){
case 'A': case 'B': case 'C':
str+='2';
break;
case 'D': case 'E': case 'F':
str+='3';
break;
case 'G': case 'H': case 'I':
str+='4';
break;
case 'J': case 'K': case 'L':
str+='5';
break;
case 'M': case 'N': case 'O':
str+='6';
break;
case 'P': case 'R': case 'S':
str+='7';
break;
case 'T': case 'U': case 'V':
str+='8';
break;
case 'W': case 'X': case 'Y':
str+='9';
break;
}
}
}
teleNum[ct++]=str;
}
sort(teleNum,teleNum+ct);
temp=teleNum[0];
total=1;
int q=1;
jug=true;
while(q<ct){
if(teleNum[q]==temp) total++;
else{
if(total>1){
for(int i=0;i<3;i++) printf("%c",temp[i]);
printf("-");
for(int i=3;i<7;i++) printf("%c",temp[i]);
printf(" %d\n",total);
jug=false;
}
temp=teleNum[q];
total=1;
}
q++;
}
if(total>1){
for(int i=0;i<3;i++) printf("%c",temp[i]);
printf("-");
for(int i=3;i<7;i++) printf("%c",temp[i]);
printf(" %d\n",total);
jug=false;
}
if(jug) printf("No duplicates.\n");
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