ACM ZOJ-2000求指导http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1000
我发现的规律是1~10 9个
10~100 9个
100~1000 90个
1000~10000 90个
然后依次类推 900 900 9000 9000 ····
我的代码现输入n确定n是在哪个范围内的第几个的数,接着构造数输出。
自己测试了一些数据都对了,可是提交上去就错了。
求各位高手解释一下我的错误··
求各位高手解释一下我的错误··
#include<stdio.h>
#include<string.h>
#include<math.h>
int fact(t)
{
int i,s=9;
for(i=1;i<t;i++)
s=s*10;
return s;
}
int main()
{
int n;
while(scanf("%d",&n)&&n)
{
if(n<10)
{
printf("%d\n",n);
continue;
}
if(n>=10&&n<=18)
{
printf("%d%d\n",n-9,n-9);
continue;
}
else
{
n=n-18;
double m=2;
int s=0;
int count=3;
while(1)
{
int t=m;
s=s+fact(t);
if(s>=n)
{
n=n-(s-fact(t));
break;
}
m=m+0.5;
count++;
}
char str[100];
int i,j;
if(count%2==0)//构造长度为偶数的回文数
{
int x=1;
for(i=1;i<count/2;i++)
x=x*10;
x=x+n-1;
printf("%d",x);
int j=0;
while(x)
{
str[j++]=x%10+'0';
x=x/10;
}
str[j]='\0';
printf("%s",str);
printf("\n");
}
if(count%2!=0)//构造长度为奇数的回文数
{
int y=1;
for(j=1;j<count/2+1;j++)
y=y*10;
y=y+n-1;
printf("%d",y);
j=0;
while(y)
{
str[j++]=y%10+'0';
y=y/10;
}
str[j]='\0';
for(i=1;i<j;i++)
printf("%c",str[i]);
printf("\n");
}
}
}
return 0;
}