2013夏休み第1週週の試合G問題の間違いの総括
1937 ワード
Description
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 Input
Input
Output
Input
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 Input
Input
10 6
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
Output
10
Input
2 1
1
10
Output
1
#include<stdio.h>
#include<string.h>
int main()
{
char s[105][105], k;
int n, a;
int i, j;
scanf("%d %c", &n, &k);
getchar(); // , getchar();
for (i = 0; i < n; i++)
{
gets(s[i]);// getchar();
}
a = k - '0';
//printf("a = %d
",a);
int len, sum = 0, x = 0, bleg = 0, t = 0;
for (i = 0; i < n; i++)
{
int f[11] = {0};// , , , , , , ;
bleg = 0; //bleg ,
len = strlen(s[i]); //printf("len s[%d] = %d
",i,len);
if (len < a + 1)
{
bleg = 0;
}
else
{
t = 0;
for (j = 0; j < len; j++)
{
int b = s[i][j] - '0'; //printf("b = %d
",b);
if (s[i][j] <= k && f[b] == 0)
{
t++; //printf("\t t = %d
",t);
f[b] = 1;
}
if (t == a + 1)
{
bleg = 1;
break;
}
}
}
if (bleg == 1)
{
sum++;
}
}
printf("%d
", sum);
return 0;
}