HDU 4287 Intelligent IME 水题

来源:互联网 发布:局域网网络硬盘软件 编辑:程序博客网 时间:2024/06/16 15:44

本想写个字典树

结果发现是个水题。。

#include <iostream>#include <cstdio>#include <cmath>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAX = 1000000 + 5;int num[MAX], val[MAX];const int mp[] = {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 map(char *str) {    int len = strlen(str), ans = 0;    for(int i = 0; i < len; i++) {        ans *= 10;        ans += mp[str[i] - 'a'];    }    return ans;}int main() {    int t, n, m;    char str[10];    scanf("%d", &t);    while(t--) {        scanf("%d%d", &n, &m);        memset(num, 0, sizeof(num));        for(int i = 0; i < n; i++)            scanf("%d", val + i);        while(m --) {            scanf("%s", str);            num[map(str)]++;        }        for(int i = 0; i < n; i++)            printf("%d\n", num[val[i]]);    }    return 0;}


0 0