Good NUmber

					***Good Number***

Let’s call a number k-good if it contains all digits not exceeding k (0, …, k). You’ve got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a).

Input
The first line contains integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 9). The i-th of the following n lines contains integer ai without leading zeroes (1 ≤ ai ≤ 109).

Output
Print a single integer — the number of k-good numbers in a.

Examples
Input
10 6
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
Output
10
Input
2 1
1
10
Output
1

题意:判断一串数字是否含有小于k的所有阿拉伯数字,输出所有符合这种形式的数据个数。
思路:可以对数据不断取余10,和除以10进行循环,直至判断结束。取的余数作为下标存进空数组中,而后对数组进行判断,若下标比k以下的数组不为1,说明该数据不符合规则。而后,对下标进行判断,判断与K+1的关系,等于k+1的时候,该数据满足规则,个数加一。直至循环结束,输出个数。
在这里插入代码片
#include"stdio.h"
#include"string.h"
int main()
{
	int n,k,a[15];
	while(~scanf("%d %d",&n,&k))
	{
		long long s;
		int j,m;
		int sum=0;
		for(int i=0;i<n;i++)
		{
			memset(a,0,sizeof(a));
			scanf("%lld",&s);
			while(s>0)
			{
				m=0;
				m=s%10;
				if(m<=k)
				{
					a[m]=1;
				}
				s/=10;
			}
			for(j=0;j<=k;j++)
			{
				if(a[j]==0)
				{
					break;
				}
			}
			if(j==k+1)
			{
				sum++;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值