zoukankan      html  css  js  c++  java
  • HDU 4287 Intelligent IME hash

    Intelligent IME

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=4287

    Description

    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.

    Sample Input

    1
    3 5
    46
    64448
    74
    go
    in
    night
    might
    gn

     

    Sample Output

    3
    2
    0

    HINT

    题意

    用9宫格敲了N次,给m个字符串,问你每次敲击,能够敲出多少个单词

    题解:

    hash或者map搞一搞

    代码

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)
    const int maxn=2501;
    #define mod 1000000009
    #define eps 1e-7
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    
    //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
    map<int,int> HH;
    string s[5101];
    map<string,int> H;
    int ans[5101];
    int main()
    {
        int k=2;
        for(int i=0;i<=25;i++)
        {
            if(i==3||i==6||i==9||i==12||i==15||i==19||i==22)
                k++;
            HH[i]=k;
        }
        int t=read();
        while(t--)
        {
            H.clear();
            memset(ans,0,sizeof(ans));
            int n=read(),m=read();
            for(int i=0;i<n;i++)
                cin>>s[i];
            string s1;
            for(int i=0;i<m;i++)
            {
                cin>>s1;
                for(int j=0;j<s1.size();j++)
                    s1[j]=char(HH[(s1[j]-'a')]+'0');
                H[s1]++;
            }
            for(int i=0;i<n;i++)
                printf("%d
    ",H[s[i]]);
        }
    }
  • 相关阅读:
    vue:自定义指令
    vue去掉严格开发,即去掉vue-cli安装时的eslint
    vue路由6:导航钩子
    vue路由5:命名视图
    vue路由3:子路由
    vue组件通信之任意级组件之间的通信
    vue中组件通信之子父通信
    令狐冲也是个情场高手啊
    Java —— 时区(夏令时)问题
    PL/SQL 如何导出INSERT语句
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4662218.html
Copyright © 2011-2022 走看看