杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer)。
杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。
不吉利的数字为所有含有4或62的号码。例如:
62315 73418 88914
都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。
你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。
Input
输入的都是整数对n、m(0<n≤m<1000000),如果遇到都是0的整数对,则输入结束。
Output
对于每个整数对,输出一个不含有不吉利数字的统计个数,该数值占一行位置。
Sample Input
1 100
0 0
Sample Output
80
#include<stdio.h>
#include<string.h>
#include<math.h>
char b[10];
int main(){
int a,b1,j1,t;
while(~scanf("%d%d",&a,&b1)){
int count= b1-a+1;
memset(b,'\0',sizeof(b));
if(a==0&&b1==0){
break;
}
for(int i=a;i<=b1;i++){
t=i;
for(int j=0;t!=0;j++){
b[j] = t%10+48;
t = t/10;
}
for(j1=strlen(b)-1;j1>=0;j1--){
if(b[j1]=='4'){
count -= pow(10,j1);
i+=pow(10,j1);
}
if(b[j1]=='6'&&b[j1-1]=='2'){
count -= pow(10,j1-1);
i+=pow(10,j1-1);
}
}
}
printf("%d\n",count);
}
return 0;
}
可以得出答案,但是超时,在于对b[i]的处理上
修改后
#include<stdio.h>
#include<string.h>
int a[1000002];
int main(){
int count,temp,m,n;
memset(a,0,sizeof(a));
for(int i=0;i<1000000;i++){
temp=i;
while(temp!=0){
if(temp%10==4||temp%100==62){
a[i]=1;
}
temp /= 10;
}
}
while(scanf("%d%d",&n,&m)){
if(n==0&&m==0){
break;
}
count = 0;
for(int i=n;i<=m;i++){
if(a[i]==0)
count++;
}
printf("%d\n",count);
}
return 0;
}