xtu ACM Eason

Eason

[ Submit Code ] [ Top 20 Runs ]
Acceteped : 16   Submit : 59
Time Limit : 1000 MS   Memory Limit : 65536 KB
 

Description

题目描述

Eason是个非常迷信的人,他喜欢数字3和6,不喜欢4和7。 如果一个数字的数码中没有4和7,而有3或者6的话,他就会喜欢这个数字。 比如,他会喜欢13,36,但是不会喜欢14,34。但对于28这种的,他就无所谓喜欢还是不喜欢。 Eason想知道区间[a,b]中一共有多少个他喜欢和不喜欢的数字?

输入

每行输入一个样例,为a和b,0≤a≤b≤106。如果a和b都为0,那么输入结束,这个样例不需要处理。

输出

每行输出一个样例的结果,先输出喜欢数字的个数,再输出不喜欢数字的个数。

样例输入

1 10 
1 100 
1 1000000 
0 0

样例输出

2 2 
28 36 
215488 737856
 

#include <cmath>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <malloc.h>
#include <stdlib.h>
using namespace std;

int cal(int n)
{
int a4,a7,a3=0,a6=0;
while(n)
{
if(n%10==3)
a3=1;
if(n%10==6)
a6=1;
if(n%10==4)
return 0;
if(n%10==7)
return 0;
n/=10;
}
if(a3==1||a6==1)
return 1;
else
return 3;
}

int main()
{
int a,b,aa,bb,i,*a1,*a2,j,k;

a1=(int*)malloc(1000005*sizeof(int));
a2=(int*)malloc(1000005*sizeof(int));


a1[0]=0;a2[0]=0;
for(i=1;i<1000001;i++)
{
k=cal(i);
switch(k)
{
case 1:a1[i]=a1[i-1]+1,a2[i]=a2[i-1]+0;break;
case 0:a2[i]=a2[i-1]+1,a1[i]=a1[i-1]+0;break;
case 3:a2[i]=a2[i-1],a1[i]=a1[i-1];break;
}
}
while(1)
{
cin>>a>>b;
if(a==0&&b==0)
return 0;
cout<<a1[b]-a1[a-1]<<" "<<a2[b]-a2[a-1]<<endl;
}
}

posted @ 2014-12-25 13:56  2013551631何攀  阅读(203)  评论(1编辑  收藏  举报