| ||||||||||
| 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 | |||||||||
Re:AC了,空间换时间,没用排序。“39320K 594MS C 890B”。代码只有30+行。In Reply To:AC了,空间换时间,没用排序。“39320K 594MS C 890B”。代码只有30+行。 Posted by:lachening at 2011-04-14 12:12:59 > 号码是7位数。开一个10000000大小的int数组。
> 如果号码是123-4567。就在数组的1234567号计数。 重复则++。
> 也就是 号码本身作为数组的下标。
> 当全部统计完以后,for(i=0;i<10000000;i++) 从最小号开始,顺序输出所有数组内容>1的情况 printf("%03d-%04d %d",下标/10000,下标%10000,数组内容);
>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int phoneNum;
int i,j,k,m=0;
int tempNum;;
int noDupli =0;
int len;
char str[100]={0};
int *flag=NULL;
char temp[100]={0};
scanf("%d",&phoneNum);
flag=(int*)malloc(10000000*sizeof(int));
memset(flag,0,10000000*sizeof(int));
for(i =0;i<phoneNum;i++)
{
scanf("%s",str);
len =strlen(str);
k=0;
for (j=0;j<len;j++)
{
if (str[j] == '-' || str[j]=='Q' || str[j]=='Z')
{
continue;
}
if (str[j]>='A' && str[j]<='C')
{
temp[k++]='2';
}
else if (str[j]>='D' && str[j]<='F')
{
temp[k++]='3';
}
else if (str[j]>='G' && str[j]<='I')
{
temp[k++]='4';
}
else if (str[j]>='J' && str[j]<='L')
{
temp[k++]='5';
}
else if (str[j]>='M' && str[j]<='O')
{
temp[k++]='6';
}
else if (str[j]>='P' && str[j]<='S')
{
temp[k++]='7';
}
else if (str[j]>='T' && str[j]<='V')
{
temp[k++]='8';
}
else if (str[j]>='W' && str[j]<='Y')
{
temp[k++]='9';
}
else if (str[j]>='0' && str[j]<='9')
{
temp[k++] =str[j];
}
}
temp[k++]='\0';
tempNum =atoi(temp);
flag[tempNum]++;
memset(temp,0,k);
}
for (i=0;i<10000000;i++)
{
if (flag[i]>1)
{
noDupli =1;
printf("%03d-%04d %d\n",i/10000,i%10000,flag[i]);
}
}
if (!noDupli)
{
printf("No duplicates.");
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator