| ||||||||||
| 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 <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
char mapping(char c)
{
if(c=='A'||c=='B'||c=='C'||c=='a'||c=='b'||c=='c') return '2';
if(c=='D'||c=='E'||c=='F'||c=='d'||c=='e'||c=='f') return '3';
if(c=='G'||c=='H'||c=='I'||c=='g'||c=='h'||c=='i') return '4';
if(c=='J'||c=='K'||c=='L'||c=='j'||c=='k'||c=='l') return '5';
if(c=='M'||c=='N'||c=='O'||c=='m'||c=='n'||c=='o') return '6';
if(c=='P'||c=='R'||c=='S'||c=='p'||c=='r'||c=='s') return '7';
if(c=='T'||c=='U'||c=='V'||c=='t'||c=='u'||c=='v') return '8';
if(c=='W'||c=='X'||c=='Y'||c=='w'||c=='x'||c=='y') return '9';
return c;
}
int main()
{
int m,n,p;
int i=0,j,k,fla=0;
int temp[1000],tem,b[1000];
char a[50],t[50],res[1000];
scanf("%d",&m);
while(i<m)
{
scanf("%s",a);
n = strlen(a);
for(j=0,k=0;j<n;j++,k++)
{
if(a[j] == '-')
{
k--;
continue;
}
t[k] = mapping(a[j]);
}
b[i] = atoi(t);
i++;
}
if(m>=0)
sort(b,b+m);
k=0;
temp[k]=0;
for(i=0;i<m;)
{
res[i]=1;
for(j=i+1;j<m;j++)
{
if(b[i] != b[j])
{
k++;
temp[k]=j;
break;
}
res[i]++;
fla=1;
}
p=res[i];
i=i+p;
}
k++;
if(fla)
for(i=0;i<k;i++)
{
j=temp[i];
if(res[j]>1)
{
p=b[j]/10000;
if(p>=100)
printf("%d-",p);
else
if(p>=10)
printf("0%d-",p);
else
printf("00%d-",p);
p=b[j]%10000;
if(p>=1000)
printf("%d",p);
else
if(p>=100)
printf("0%d",p);
else
if(p>=10)
printf("00%d",p);
else
printf("000%d",p);
printf(" %d\n",res[j]);
}
}
else
printf("No duplicates.\n");
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator