TT數鴨子

問題描述

這一天,TT因爲疫情在家憋得難受,在雲吸貓一小時後,TT決定去附近自家的山頭遊玩。

TT來到一個小湖邊,看到了許多在湖邊嬉戲的鴨子,TT頓生羨慕。此時他發現每一隻鴨子都不一樣,或羽毛不同,或性格不同。TT在腦子裏開了一個map<鴨子,整數> tong,把鴨子變成了一些數字。現在他好奇,有多少隻鴨子映射成的數的數位中不同的數字個數小於k。

Input

輸入第一行包含兩個數n,k,表示鴨子的個數和題目要求的k。

接下來一行有n個數,aia_i ,每個數表示鴨子被TT映射之後的值。

Output

輸出一行,一個數,表示滿足題目描述的鴨子的個數。

無行末空格

Sample input

6 5
123456789 9876543210 233 666 1 114514

Sample output

4

數據範圍

在這裏插入圖片描述

解題思路

這道題的數據範圍就是一個坑,其實k最大也就是10,考慮到這裏,這個題就十分簡單。通過mod 10的方法取得每一位,最後統計出現過的數字個數就可以了。

完整代碼

//#pragma GCC optimize(2)
//#pragma G++ optimize(2)
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <climits>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

const int maxn=11;
int n,k,a[maxn],ans;
int getint(){
    int x=0,s=1; char ch=' ';
    while(ch<'0' || ch>'9'){ ch=getchar(); if(ch=='-') s=-1;}
    while(ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar();}
    return x*s;
}
int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    scanf("%d %d",&n,&k);
    for (int i=1; i<=n; i++){
        long long x=0;
        scanf("%lld",&x);
        while(x){
            a[x%10]++;
            x/=10;
        }
        int temp=0;
        for (int j=0; j<10; j++){
            if(a[j]) {
                temp++; a[j]=0;
            }
        }
        if(temp<k) ans++;
    }
    printf("%d\n",ans);
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章