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);    
        }
    }
}

转载于:https://www.cnblogs.com/LZYY/p/3439454.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值