首页 > 其他分享 >HDU - 7125 Master of Shuangpin

HDU - 7125 Master of Shuangpin

时间:2023-04-13 23:01:26浏览次数:42  
标签:HDU Shuangpin wo pinyin Master mp output input 7125

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.

[h]
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".

Input

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.

Output

The keys sequence separated by spaces.

Examples input
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
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

相关文章

  • HDU 2222 Keywords Search (AC自动机)
    题目地址:HDU2222AC自动机第一发!真好奇这些算法是怎么被发明的。。算法的魅力真是无穷。这题是AC自动机模板题。自己实在写不出来,比着kuangbin的模板写的==代码如下:#include<iostream>#include<string.h>#include<math.h>#include<queue>#include<algorithm>#incl......
  • HDU 4313 Matrix (贪心)
    题目地址:HDU4313利用最小生成树的思想,这里是从大往下删,能删则删,不能删就留着。用个并查集维护下。代码如下:#include<iostream>#include<string.h>#include<math.h>#include<queue>#include<algorithm>#include<stdlib.h>#include<map>#include<set>......
  • HDU 4628 Pieces (状压DP)
    题目地址:HDU4628这题没想到怎么快速枚举子状态。。。看了题解才知道的。用for(state=i;state>0;state=(state-1)&i)就可以了。这题的具体做法是先预处理出所有的状态是不是回文串,然后就是普通的DP了。代码如下:#include<iostream>#include<string.h>#include<math.h>......
  • HDU 4812 D Tree (树上点分治)
    题目地址:HDU4812这题是13年南京区域赛的现场题。树分治思想。树分治的过程中记录下每个子树的所有到达根的路径的积,用best记录下每个积的最小端点,然后再枚举当前子树的每个积,然后用逆元的方法求出当积为k时所需要的另一个端点值,并更新答案。代码如下:#include<iostream>#......
  • HDU 5145 NPY and girls (莫队分块离线)
    题目地址:HDU5145莫队真的好神奇。。这样的复杂度居然只有n*sqrt(n)。。。裸的莫队分块,先离线,然后按左端点分块,按块数作为第一关键字排序,然后按r值作为第二关键字进行排序。都是从小到大,可以证明这样的复杂度只有n*sqrt(n)。然后进行块之间的转移。代码如下:#include<ios......
  • HDU 5016 Mart Master II (树上点分治)
    题目地址:HDU5016先两遍DFS预处理出每个点距最近的基站的距离与基站的编号。然后找重心,求出每个点距重心的距离,然后根据dis[x]+dis[y]<d[y],用二分找出当前子树中不会被占领的数量,总点数减去即是被占领的数量。这样就可以求出每个点最多占领的点的数量。然后找最大值即可。......
  • HDU 1452 Happy 2004 (积性函数)
    题目地址:HDU1452性质1:如果gcd(a,b)=1则S(a*b)=S(a)*S(b)2004^X=4^X*3^X*167^XS(2004^X)=S(2^(2X))*S(3^X)*S(167^X)性质2:如果p是素数则S(p^X)=1+p+p^2+…+p^X=(p^(X+1)-1)/(p-1)因此:S(2004^X)=(2^(2X+1)-1)*(3^(X+1)-1)/2*(167^(X+1)-1)/166......
  • HDU 4864Task(多校联合训练1)(贪心)
    题目地址:HDU4864这题又是一上来认为是最小费用流,但是边太多,果然,敲完交上去后不断TLE。。小优化了两次也没过。。。sad。。后来看了题解才发现是贪心。。。贪心也不好想。大体思路是很好想的,就是先都按时间从大到小排序,再遍历任务,从机器里找能匹配的,并在能匹配的里边找等级尽量小的......
  • HDU 1864最大报销额(一维背包)
    题目地址:HDU1864刚上来看着挺麻烦的。。仔细看了看原来好简单好简单。。。只要去掉一些不符合要求的发票,剩下的就是最简单的背包问题了。。对于小数问题,只要*100就变成整数了。代码如下:#include<algorithm>#include<iostream>#include<cstring>#include<cstdlib>#include......
  • HDU 5045 Contest(费用流)
    题目地址:HDU5045终于在比赛中用网络流A了一道题。。。刷了那么多网络流,终于用到一次了。。虽然题目很简单,但是还是要纪念一下下。。。我这题的思路就是求m/n次费用流,每n个算作同一轮,对这同一轮的求最大费用流。建图就很简单了,最简单的二分图模型。代码如下:#include<iostre......