不吉利的数字为所有含有4或38的号码

不吉利的数字为所有含有4或38的号码。例如:
38315 73418 88914
都属于不吉利号码。但是,311582虽然含有3和8,但不是38连号,所以不属于不吉利数字之列。
你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。
输入
输入的都是整数对n、m(0<n≤m<1000000),如果遇到都是0的整数对,则输入结束。
输出
对于每个整数对,输出一个不含有不吉利数字的统计个数,该数值占一行位置。
样例输入
1 100
0 0
样例输出
80

在这里插入代码片
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
// // 拷贝到平台的时候把my_fuction_lib.h注释掉.
//#include "my_fuction_lib.h"
//在此下方插入自定义函数对的声明:
/* 取出读入的数据的数码: */
int fetch_num_char(int n,int *num_char)
{
int i = 0;
int cnt=0;
for(;n>0;)
{
num_char[i++] = n%10;
n /= 10;
cnt++;
}
for(i = 0;i<cnt/2;i++)
{
int temp;
temp = num_char[i];
num_char[i] = num_char[cnt-1-i];
num_char[cnt-1-i] = temp;
}
return cnt;
}
int is_bad_num(int *num,int n)
{
/* 由于一下两个标准边界不一 */
/* 监测4 */
for(int j= 0;j<n;j++)
{
if(num[j] == 4)
return 1;
}
/* 监测38 */
for(int i= 0;i < n -1;i++)
{
if( (num[i] == 3) && (num[i+1] == 8) )
{
return 1;
}
}
return 0;
}
//主函数main
int main()
{
//复制模版式删除这个或者再下面一个
int n,m;
int len_number;
int num_char[100];
while( scanf("%d%d",&n,&m) ,n != 0 || n != 0)
{
int good_number = 0;
for(int i = n;i<m+1;i++)
{
len_number = fetch_num_char(i,num_char);
if(! is_bad_num(num_char,len_number) )
{
good_number++;
}
}
printf("%d\n",good_number);
}
return 0;
}
posted @   xuchaoxin1375  阅读(15)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示