HDU - 7125 Master of Shuangpin
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".
There 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.
The keys sequence separated by spaces.
rua
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
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
ni you ben shi na lai mai a
wo e le wo men chi shen me
ang yang de dou zhi
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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人