问题描述
这一天,TT因为疫情在家憋得难受,在云吸猫一小时后,TT决定去附近自家的山头游玩。
TT来到一个小湖边,看到了许多在湖边嬉戏的鸭子,TT顿生羡慕。此时他发现每一只鸭子都不一样,或羽毛不同,或性格不同。TT在脑子里开了一个map<鸭子,整数> tong,把鸭子变成了一些数字。现在他好奇,有多少只鸭子映射成的数的数位中不同的数字个数小于k。
Input
输入第一行包含两个数n,k,表示鸭子的个数和题目要求的k。
接下来一行有n个数, a i a_i ai ,每个数表示鸭子被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;
}