time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Sample test(s)
input
10 6 1234560 1234560 1234560 1234560 1234560 1234560 1234560 1234560 1234560 1234560
output
10
input
2 1 1 10
output
1
解题说明:此题的意思是指定一个k,判断一个字符串中是否只出现0-k-1这k个数字。做法是统计出现过的每个数字,然后加以判断即可。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include <cstring>
using namespace std;
int main()
{
int n, k,count=0;
int arr[101], i, j;
scanf("%d %d", &n, &k);
for (i = 0; i<n; i++)
{
scanf("%d", &arr[i]);
int hash[10] = { 0 };
while (arr[i])
{
hash[arr[i] % 10] = 1;
arr[i] /= 10;
}
for (j = 0; j <= k; j++)
{
if (!hash[j])
{
break;
}
}
if (j == k + 1)
{
count++;
}
}
printf("%d\n", count);
return 0;
}