WOJ1229-Cow Counting

农夫约翰要为他的N头牛编号,但牛不喜欢包含数字L的编号。他需要找出最小的一组正整数编号,且这些编号中不包含数字L。问题在于确定约翰必须写在最大编号的牛身上的最大数字是多少。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Farmer John wants to label his N (1 <= N <= 1,000,000) cows, but
cows don't like having the digit L (0 <= L <= 9) written on them,
so he avoids that.

If the cows are labeled with the smallest set of N positive integers
that don't have the digit L, what is the largest number that Farmer
John has to write on any cow?

输入格式

Line 1: Two space-separated integers: N and L.

输出格式

Line 1: A single integer that is the largest number that Farmer John has to write on any cow.

样例输入

10 1

样例输出

22


#include<stdio.h>
int n,l;
int main(){
	int i,cnt,num,s,flag;
	while(scanf("%d %d",&n,&l)!=EOF){
		cnt=0;
		for(i=1;;i++){
			num=i;
			flag=1;
			while(num>0){
				s=num%10;
				if(s==l){
					flag=0;
					break;
				}
				num=num/10;
			}
			if(flag){
				cnt++;
				if(cnt==n)
				break;
			}
			else
			continue;
		}
		printf("%d\n",i);
	}
	return 0;
}
 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值