| ||||||||||
| 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为什么过不了#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
int main()
{
int number;
scanf("%d",&number);//电话号码的个数
char phonumber[100][20];//二维数组存储输入的电话号码
int i,j,temp,length;
for(i=0;i<number;i++)
{
scanf("%s",phonumber[i]);//以字符串输入电话号码
temp=0,j=0,length=strlen(phonumber[i]);
while(j<length)
{
if(phonumber[i][j]=='-')
j++;
else
{
if(phonumber[i][j]>='A'&&phonumber[i][j]<='Z')
{
if('A'<=phonumber[i][j]&&phonumber[i][j]<='C')
phonumber[i][temp]='2';
if('D'<=phonumber[i][j]&&phonumber[i][j]<='F')
phonumber[i][temp]='3';
if('G'<=phonumber[i][j]&&phonumber[i][j]<='I')
phonumber[i][temp]='4';
if('J'<=phonumber[i][j]&&phonumber[i][j]<='L')
phonumber[i][temp]='5';
if('M'<=phonumber[i][j]&&phonumber[i][j]<='O')
phonumber[i][temp]='6';
if('P'<=phonumber[i][j]&&phonumber[i][j]<='S')
phonumber[i][temp]='7';
if('T'<=phonumber[i][j]&&phonumber[i][j]<='V')
phonumber[i][temp]='8';
if('W'<=phonumber[i][j]&&phonumber[i][j]<='Y')
phonumber[i][temp]='9';
}
else
phonumber[i][temp]=phonumber[i][j];
temp++;
j++;
}
}
if(length>7)
phonumber[i][7]='\0';//转换后的电话号码占有前七个个存储单元
}
int *a,count;
a=(int *)malloc(number*sizeof(int));
for(i=0;i<number;i++)
{
a[i]=atoi(phonumber[i]);//字符串转换成整型变量
}
for(i=0;i<number;i++)//将电话号码升序排列
{
for(j=i;j<number;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
i=0;
int leap=0;
while(i<number)//输出
{
count=1;
j=i+1;
while(j<number)
{
if(a[i]==a[j])
{
count++;
j++;
}
else
{
if(count>1)
{
printf("%d-%d %d\n",a[i]/10000,a[i]%10000,count);
leap=1;
}
i=j;
break;
}
}
if(j>=number)
{
if(count>1)
{
printf("%d-%d %d\n",a[i]/10000,a[i]%10000,count);
leap=1;
}
i=j;
}
}
if(leap==0)
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