题目1 : 热门号码
时间限制:
10000ms
单点时限:
1000ms
内存限制:
256MB
-
3 2 HIHO IGGO CODER 4446 26337
样例输出
-
2 1
描述
1 2 3 ABC DEF 4 5 6 GHI JKL MNO 7 8 9 PQRS TUV WXYZ * 0 #
我们知道电话拨号盘上数字会有若干字母对应,例如2对应ABC,7对应PQRS。
这是因为在北美尤其是在美国,一些大公司常常把代表其企业名称、产品名称、行业名称等的特定英文单词或字母组合嵌入其电话号码中。比如,苹果公司在线商店Apple Store的订购电话是:1-800-MY-APPLE (1-800-692-7753)。这种做法的主要目的在于宣传公司标志并且便于受众记忆和使用。显然对于英语国家的人们来说,英文单词要比凌乱的数字更容易识记。
多个字母组合可能会对应同一个号码,从而造成争抢,例如HIHO和IGGO都对应4446。
现在给定N个字母组合以及M个号码,请对每一个号码求出有多少个字母组合对应它。
输入
第一行包含两个整数N和M。
以下N行每行一个字母组合。
再之后M行每行一个数字号码。
对于30%的数据,1 ≤ N, M ≤ 100
对于100%的数据,1 ≤ N, M ≤ 50000, 字母组合和号码的长度都不超过10。只包含大写字母和数字2-9。
输出
输出M行。按照输入的顺序依次输出每一个号码有多少字母组合对应。
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <bits/stdc++.h>
using namespace std;
int N,M;
int character[26]={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};
map<long long,int>MAP;
int main(){
cin>>N>>M;
for(int i=0;i<N;i++){
string s;
cin>>s;
long long cur=0;
for(int j=0;j<s.length();j++){
cur*=10;
cur+=character[s[j]-'A'];
}
if(MAP.find(cur)==MAP.end())MAP.insert(make_pair(cur,1));
else MAP[cur]=MAP[cur]+1;
}
for(int i=0;i<M;i++){
long long cur;
cin>>cur;
if(MAP.find(cur)==MAP.end())cout<<0<<endl;
else cout<<MAP[cur]<<endl;
}
return 0;
}
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
// | | \\\ - /// | |
// | \_| ''\---/'' |_/ |
// \ .-\__ '-' ___/-. /
// ___'. .' /--.--\ `. .'___
// ."" '< `.___\_<|>_/___.' >' "".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `_. \_ __\ /__ _/ .-` / /
// =====`-.____`.___ \_____/___.-`___.-'=====
// `=---='
//
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// 佛祖保佑 永无BUG
//
//
//