题意:输入n,m,n个目标数,m个匹配数,求出每个目标数与匹配数相同的个数,没有的话为0
思路:排序检索题,,可以把字符串转化为整数,然后再检索是否相同
#include<stdio.h>
#include<string.h>
int change[] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9};
int main() {
int cas;
int arr[5005], num[5005], vis[5005];
char str[10];
scanf("%d", &cas);
while (cas--) {
int n, m;
int temp, cnt = 0;
memset(vis, 0, sizeof(vis));
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++)
scanf("%d", &arr[i]);
while (m--){
temp = 0;
scanf("%s", str);
for(int i = 0; i < strlen(str); i++){
temp = temp * 10 + change[str[i] - 'a'];
}
num[cnt++] = temp;
}
for(int i = 0; i < n; i++){
for(int j = 0; j < cnt; j++)
if (arr[i] == num[j])
vis[i]++;
}
for(int i = 0; i < n; i++)
printf("%d\n", vis[i]);
}
return 0;
}