CF#213DIV2:A Good Number

2014-11-24 02:32:47 · 作者: · 浏览: 1
Let's call a number k-good if it contains all digits not exceedingk (0, ..., k). You've got a numberk and an array a containingn numbers. Find out how many k-good numbers are in a (count each number every time it occurs in arraya).
Input
The first line contains integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 9). The i-th of the followingn lines contains integer ai without leading zeroes (1 ≤ ai ≤ 109).
Output
Print a single integer — the number of k-good numbers ina.
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
题意:给出n和k,找出n个数中含有0~k这些数字的数有几个
水题,一开始没理解题意,真坑
#include   
#include   
#include   
using namespace std;  
  
int main()  
{  
    int n,k,i,ans,j;  
    char str[1000];  
    while(~scanf("%d%d",&n,&k))  
    {  
        ans = 0;  
        for(i = 1;i<=n;i++)  
        {  
            scanf("%s",str);  
            int len = strlen(str);  
            int cnt = 0;  
            for(j = 0;j<=k;j++)  
            {  
                char s[10];  
                s[0] = j+'0';  
                s[1] = '\0';  
                if(!strstr(str,s))  
                break;  
            }  
            if(j>k)  
            ans++;  
        }  
        printf("%d\n",ans);  
    }  
  
    return 0;  
}