Good Number

Time Limit: 1000ms

Problem 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 input includes several cases. For each case, the input format is:
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:

For each case, Print a single integer — the number of k-good numbers in a.

Sample Input:

10 6
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
2 1
1
10
2 0
10
20

Sample Output:

10
1
2
感触:做了很久,没有ac不了的水题!!!!
 
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int i,j;
Scanner cin = new Scanner(System.in);
while(cin.hasNext())
{
int num = 0;
int n = cin.nextInt(); //测试数据
int m = cin.nextInt(); //不能超过的数
while(n!=0)
{
int x = cin.nextInt();
String st = Integer.toString(x, 10); //转换成字符
int a = st.length();
boolean h[] = new boolean[m+1];
for(j=0;j<a;j++) //检查这个数是否包含从0到m的数
{
for(i=0;i<=m;i++) //
{
int t = ((int)st.charAt(j)-(int)('0'));
if( t== i) //判断每一位是否都大于那个数
h[i] = true;
}
}
int flag =1;
for(i=0;i<=m;i++)
{
if(h[i]!=true)
flag =0;
}
if(flag==1)num++;
n--; }
System.out.println(num);
}
}
}
上一篇:集中式版本控制VS分布式版本控制


下一篇:Executors线程池