| ||||||||||
| 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 | |||||||||
我郁闷,有没有高手可以指点一下?错了1晚上了!!实在想不出特殊情况,例子是通过了.
#include <stdio.h>
void main()
{
char s[200];
long n,sum,xinxi[20000],num=0,hello;
int i,j,geshu[20000],temp,sign;
scanf("%ld",&n);
getchar();
while(n-->0)
{
gets(s);
sum=0;
for (i=j=0;;i++)
{
if (s[i]>='0'&&s[i]<='9'||(s[i]>='A'&&s[i]<='Z'))
{
switch(s[i])
{
case 'A':case 'B':case 'C':sum=sum*10+2;break;
case 'D':case 'E':case 'F':sum=sum*10+3;break;
case 'G':case 'H':case 'I':sum=sum*10+4;break;
case 'J':case 'K':case 'L':sum=sum*10+5;break;
case 'M':case 'N':case 'O':sum=sum*10+6;break;
case 'P':case 'R':case 'S':sum=sum*10+7;break;
case 'T':case 'U':case 'V':sum=sum*10+8;break;
case 'W':case 'X':case 'Y':sum=sum*10+9;break;
default:sum=sum*10+s[i]-'0';break;
}
j++;
}
if (j==7)
break;
}/*读串*/
sign=i=0,j=num-1;
while(i<=j)
{
temp=(i+j)/2;
if (xinxi[temp]>sum)
j=temp-1;
else if (xinxi[temp]<sum)
i=temp+1;
else
{
sign=1;
break;
}
}/*二分搜索是否存在*/
if (sign==0||num==0)
{
for (i=num-1;i>=0&&sum<xinxi[i];i--)
{
xinxi[i+1]=xinxi[i];
geshu[i+1]=geshu[i];
}
xinxi[i+1]=sum;
geshu[i+1]=1;
num++;/*插入并按增序排序*/
}
else geshu[temp]++;
}
sign=0;
for (i=0;i<num;i++)
{
if (geshu[i]>=2)
{
hello=xinxi[i];
for (j=6;j>=0;j--)
{
s[j]=hello%10+'0';
hello/=10;
}
s[7]='\0';
printf("%c%c%c-%s %d\n",s[0],s[1],s[2],&s[3],geshu[i]);
sign=1;
}
}
if (sign==0)
printf("No duplicates.\n");/*按要求打印*/
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator