http://acm.split.hdu.edu.cn/showproblem.php?pid=2089
#include<stdio.h>
#include<string.h>
int luck(int x)
{
while(x)
{
if(x%10==4||x%100==62)
{
return 0;
}
x/=10;
}
return 1;
}
int x[1000005];
int main()
{
int i,n,m,s;
for(i=1;i<1000005;i++)
{
x[i]=x[i-1]+luck(i); //这个地方写得太好看了
}
while(scanf("%d%d",&n,&m)&&(n||m))
{
printf("%d\n",x[m]-x[n-1]);
}
return 0;
}
#include<stdio.h> //方法二
#include<string.h>
int check(int x)//判断
{
while(x)
{
if(x%10==4)
return 1;
if(x%100==62)
return 1;
x/=10;
}
return 0;
}
int s[1000005];
void example()//打表
{
int a;
for(a=1;a<1000005;a++)
{
if(check(a)==0)//记录不是不吉利数字的数量
s[a]=s[a-1]+1;
else
s[a]=s[a-1];
}
}
int main()
{
int m,n;
memset(s,0,sizeof(s));
example();
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0)
break;
printf("%d\n",s[m]-s[n-1]);
}
return 0;
}
<pre name="code" class="objc">#include<stdio.h>//不能运行
int check(int x)
{
int a;
while(x)
{
a=x%10;
if(a==4)
return 1;
else if(a==4&&(x%100)/10==6)
return 1;
x/=10;
}
return 0;
}
int main()
{
int d[1000000],a,b,i;
while(EOF!=scanf("%d%d",&a,&b)&&(a||b))
{
d[1]=1;
for(i=2;i<=b;i++)
{
if(check(i))
d[i]=d[i-1];
else
d[i]=d[i-1]+1;
}
printf("%d\n",d[b]-d[a-1]);
}
return 0;
}
<pre name="code" class="objc">#include<stdio.h>//方法三!
#include<string.h>
<span style="color:#FF0000;">int ant[1000000];</span>
int dis(int a)
{
int i,j;
while(a)
{
i=a%10;
j=(a/10)%10;
a/=10;
if(i==4) //如果是不好的数4或者62就返回1
return 1;
if(j==6&&i==2)
return 1;
}
return 0; //好的数返回0
}
int main()
{
int i,a,b,num;
memset(ant,0,sizeof(ant));
for(i=2;i<=1000000;i++)
{
if(dis(i))
ant[i]=ant[i-1]; //打表,先算出1到每个数间有多少个好的数;返回1不加与上一个数相等
else
ant[i]=ant[i-1]+1;
}
while(~scanf("%d %d",&a,&b)&&(a||b))
{
num=ant[b]-ant[a];
if(dis(a)==0) //判断最左边的数是不是不好的数,不是加1
num++;
printf("%d\n",num);
}
return 0;
}
#include<stdio.h>//未知错误#include<string.h>#include<stdlib.h>int s[1000001];int main(){int a,b,i;char c[10];s[0]=0;for(i=1;i<=1000000;i++){s[i]=s[i-1];itoa(i,c,10);if(strstr(c,'62')!=NULL || strstr(c,'4')!=NULL) continue;else s[i]++;}while(scanf('%d%d',&a,&b)!=EOF){if(a==0 && b==0) break;printf('%d\n',s[b]-s[a-1]);}return 0;}