We all use cell phone today. And we must be familiar with the intelligent English input method on the cell phone. To be specific, the number buttons may correspond to some English letters respectively, as shown below: 
  2 : a, b, c    3 : d, e, f    4 : g, h, i    5 : j, k, l    6 : m, n, o     
  7 : p, q, r, s  8 : t, u, v    9 : w, x, y, z 
  When we want to input the word “wing”, we press the button 9, 4, 6, 4, then the input method will choose from an embedded dictionary, all words matching the input number sequence, such as “wing”, “whoi”, “zhog”. Here comes our question, given a dictionary, how many words in it match some input number sequences?

Input

  First is an integer T, indicating the number of test cases. Then T block follows, each of which is formatted like this: 
  Two integer N (1 <= N <= 5000), M (1 <= M <= 5000), indicating the number of input number sequences and the number of words in the dictionary, respectively. Then comes N lines, each line contains a number sequence, consisting of no more than 6 digits. Then comes M lines, each line contains a letter string, consisting of no more than 6 lower letters. It is guaranteed that there are neither duplicated number sequences nor duplicated words.

Output

  For each input block, output N integers, indicating how many words in the dictionary match the corresponding number sequence, each integer per line.

文章大意:手机键盘中与数字2相对应的字母有a,b,c;3相对应的字母有d,e,f。给出一些数字串如34,和一些小写字母串。求小写字母对应的数字串出现的次数。字符串abc对应的数字串是111,dh对应的数字串是34。则小写字符串中111出现一次,34出现一次。

自己跳进的坑:因为是T组输入,所以也要给tree数组清零,emmmm。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int a[10];int cnt[500005];
int tree[500003][12],sum[500003];
char s[15];
int tot,len,rt;
void init()
{
    memset(sum,0,sizeof(sum));
    memset(cnt,0,sizeof(cnt));
    memset(tree,0,sizeof(tree));
    tot=0;
}
int Getnum(char ch)
{
    if(ch>='a'&&ch<='c')
        return 2;
   else if(ch>='d'&&ch<='f')
        return 3;
   else if(ch>='g'&&ch<='i')
        return 4;
   else if(ch>='j'&&ch<='l')
        return 5;
   else if(ch>='m'&&ch<='o')
        return 6;
    else if(ch>='p'&&ch<='s')
        return 7;
    else if(ch>='t'&&ch<='v')
        return 8;
    else
        return 9;
}
void insert(int v)
{
    len=strlen(s);
    rt=0;
    for(int i=0;i<len;i++)
    {
        int id=s[i]-'0';
        if(!tree[rt][id])
        {
          // memset(tree[tot],0,sizeof(tree[tot]));
          //   sum[rt]=0;
             tree[rt][id]=++tot;
        }

rt=tree[rt][id];
    }
    sum[rt]=v;
   // printf("%d#\n",sum[rt]);
}
int Find(char *s)
{
    rt=0;
    len=strlen(s);
    for(int i=0;i<len;i++)
    {
        int id=Getnum(s[i]);
       // printf("%d**\n",id);
        if(!tree[rt][id])
            return 0;
        rt=tree[rt][id];
    }
   // printf("#%d\n",sum[rt]);
    return sum[rt];
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        init();
        //memset(cnt,0,sizeof(cnt));
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
        {
            scanf("%s",s);
            insert(i);
        }
        for(int i=1;i<=m;i++)
        {
            scanf("%s",s);
            cnt[Find(s)]++;
        }
        for(int i=1;i<=n;i++)
            printf("%d\n",cnt[i]);
    }
    return 0;
}

HDU -4287 Intelligent IME 字典树数组模拟相关推荐

  1. [ACM] hdu 1671 Phone List (字典树)

    [ACM] hdu 1671 Phone List (字典树) Phone List Problem Description Given a list of phone numbers, determ ...

  2. hdu 1298 字典树 + DFS (模拟T9文本输入)

    题意:       给你一些按键顺序,让你输出每一步中概率最大的那个单词,这里的概率计算方 法好好看看别弄错了,一开始就是因为弄错了,各种wa,比如 abc 1 ,ab 1,那么 ab 的概率就是2 ...

  3. HDU - 1251 统计难题(字典树)

    题目链接:点击查看 题目大意:给出一些单词,后续再给出一些前缀,询问包含此前缀的单词一共有多少个 题目分析:这个题目的数据可能有点水,而且时间给的也很足,给了两秒,而且加上是hdu的,可以用无序map ...

  4. HDU - 4825 Xor Sum(字典树)

    题目链接:点击查看 题目大意:给出n个数组成的数组,再给出m个询问,每次询问给出一个x,要求从数组中选出一个k,使得k^x的值最大 题目分析:字典树求异或值最大的模板题,对于n个数直接insert到字 ...

  5. CodeForces - 979D Kuro and GCD and XOR and SUM(字典树+暴力+模拟)

    题目链接:点击查看 题目大意:说实话看到这么复杂而且还是英文的题面我是拒绝的,但题还是得补啊,就去百度找的题解看题意,题意大概是这样的: 给出n个操作,每个操作分为两种类型: 1 x:向集合中插入x ...

  6. hdu 1251 统计难题 (字典树入门题)

    1 /******************************************************* 2 题目: 统计难题 (hdu 1251) 3 链接: http://acm.hd ...

  7. 字典树-数组指针实现+数组实现

    提出问题 给定一个字符串集合W,然后询问该集合中是否存在字符串S. eg:W={"acd","bcd","abcd","abcde ...

  8. 2019 杭电多校 HDU - 6625 three arrays 字典树+贪心

    题目链接:https://cn.vjudge.net/problem/HDU-6625 题意:a和b两个数组n个数,数字任意组合异或,求得到c数组的字典序最小 题解:对于两个数组从高位到低位建立两个字 ...

  9. HDU 1251 统计难题 字典树/STL

    统计难题 Time Limit:2000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Description Ig ...

最新文章

  1. Redis入门教程(一)
  2. 解决Button设置disabled后无法执行后台代码问题
  3. ubuntu下sogou突然不能用
  4. xshell vim 不能粘贴_linux基础知识:vim(vi)的知识
  5. 奏响春的序曲,「武汉的春天」让人泪目
  6. python selenium实现百度搜索
  7. UEBA能够检测的七大类安全风险
  8. 使用junit4测试spring项目中service方法
  9. 小米路由器安装Misstar tools 和MIXBOX
  10. Python+Django+Hadmin的初级使用
  11. cmd 卸载mysql_彻底卸载MySQL图文教程
  12. 计算机与现代社会英语作文,急求英文翻译 随着现代社会的发展,人工智能已经逐步进入了我们的生活。人工智能带给了我们生活无穷的便...
  13. Springboot @Aspect
  14. 2021-2025年中国共享Web托管服务行业市场供需与战略研究报告
  15. 这可能是最全最好的BLAST教程
  16. MATLAB离散点边界曲线的绘制
  17. sketchb必备快捷键大全,sketch如何自定义快捷键
  18. 解决在SQLYog中执行SQL语句会提示错误的信息,但数据能查出来
  19. win10右键文件夹卡死未响应的解决方法
  20. UEFI开发探索94 – 迷宫小游戏

热门文章

  1. Checksum: 0x7259 [incorrect, should be 0x0a75 (maybe caused by TCP checksum offload?)]
  2. Android热修复技术选型——三大流派解析
  3. seaborn几种图的解释
  4. AutoCAD2014简体中文版安装破解步骤
  5. 敲实用的视频小插件,你确定不瞄一眼吗~
  6. webpack-dev-server实现静态资源加载和proxy代理
  7. 基于物联网技术的水质监测方案
  8. 金蝶云·星空——应付暂估冲回模式下存货对账
  9. Memos:一款开源的超高颜值备忘录,GitHub 星标 6.3k
  10. 用java写一个日期相减方法