D. Master of Shuangpin time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output
As you know, there are three kinds of Chinese input methods commonly used: Wubi, Pinyin and Shuangpin. With Shuangpin, you can type any Chinese word by pressing keys only twice.
Pinyin | Sequence | Pinyin | Sequence |
q, iu | q | f, en | f |
w, ei | w | g, eng | g |
e | e | h, ang | h |
r, uan | r | j, an | j |
t, ue | t | k, uai, ing | k |
y, un | y | l, uang, iang | l |
u, sh | u | z, ou | z |
i, ch | i | x, ia, ua | x |
o, uo | o | c, ao | c |
p, ie | p | v, zh, ui | v |
a | a | b, in | b |
s, ong, iong | s | n, iao | n |
d, ai | d | m, ian | m |
Attention that:
- For pinyin of length 1, you should repeat it in order to meet the conditions.
- For those of length 2, just output the original pinyin.
- For pinyin such as ang, you should press the first character of it and then look up this whole pinyin in the table for the second key.
- For simplification, there is no character v in any input. We believe that you, a Pinyin master, can tell u and v in any situations such as lve and que, so we do not challenge you here.
OK, now you are already a MASTER of Shuangpin! Please output the keys sequence to type the given sentences. For example, "ni hao shi jie" will be "ni hc ui jp".
InputThere are multiple test cases. Each line contains one.
Each line is a sequence of pinyin separated by spaces.
It is guaranteed that the number of test case is no more than 1000, the number of pinyin in one test case is no more than 500, and the number of pinyin in all the test cases is no more than 5000.
OutputThe keys sequence separated by spaces.
Examples inputrua
ni xian qi po lan
rang wo men dang qi shuang jiang
cha na zhua zhu le wei lai
zhe ti mian shen me wan yi
output
rx
ni xm qi po lj
rh wo mf dh qi ul jl
ia na vx vu le ww ld
ve ti mm uf me wj yi
input
ni you ben shi na lai mai a
wo e le wo men chi shen me
ang yang de dou zhi
output
ni yz bf ui na ld md aa
wo ee le wo mf ii uf me
ah yh de dz vi
代码实现:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<unordered_map>
using namespace std;
#define int long long
unordered_map<string,char>mp;
void init(){
mp["iu"]='q',mp["ei"]='w',mp["uan"]='r',mp["ue"]='t',mp["un"]='y',mp["sh"]='u',mp["ch"]='i';
mp["uo"]='o',mp["ie"]='p',mp["ong"]='s',mp["iong"]='s',mp["ai"]='d',mp["en"]='f',mp["eng"]='g';
mp["ang"]='h',mp["an"]='j',mp["uai"]='k',mp["ing"]='k',mp["uang"]='l',mp["iang"]='l',mp["ou"]='z';
mp["ia"]='x',mp["ua"]='x',mp["ao"]='c',mp["zh"]='v',mp["ui"]='v',mp["in"]='b',mp["iao"]='n',mp["ian"]='m';
char c='a';
for(int i=0;i<26;i++){
string s="";
s+=c;
mp[s]=c;
c=c+1;
}
}
signed main(){
string s;
init();
while(cin>>s){
if(s.size()==1)cout<<s<<s;
else if(s.size()==2)cout<<s;
else{
if(mp.find(s)!=mp.end())cout<<s[0]<<mp[s];
else{
for(int i=1;i<s.size();i++){
string s1=s.substr(0,i);
string s2=s.substr(i);
if(mp.find(s1)!=mp.end()&&mp.find(s2)!=mp.end()){
cout<<mp[s1]<<mp[s2];
}
}
}
}
char c=getchar();
cout<<c;
}
return 0;
}
标签:HDU,Shuangpin,wo,pinyin,Master,mp,output,input,7125 From: https://www.cnblogs.com/hxss/p/17316881.html