HDU - 7125
AYIT609第一周周赛(2021)
Problem Description
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.
Attention that:
1: For pinyin of length 1, you should repeat it in order to meet the conditions.
2: For those of length 2, just output the original pinyin.
3: 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.
4: 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.
Sample 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
ni you ben shi na lai mai a
wo e le wo men chi shen me
ang yang de dou zhi
Sample 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
ni yz bf ui na ld md aa
wo ee le wo mf ii uf me
ah yh de dz vi
题意:拼音转双拼
思路:用map<string,string>
失误点1:字符串数组a和字符串b没有按图里的一一对照好
失误点2:没把题中条件看全,单个字符输出两边,只有韵母的输出首字母和对应的字符
反思:好的精气神能事半功倍,反之事倍功半
#include<cstdio>
#include<map>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
char a[][5]={"iu","ei","uan","ue","un","uo","ie","ong","iong","ai","en","eng","ang","an","uai","ing","uang","iang","ou","ia","ua","ao","ui","in","iao","ian"};
//因为声母大多数是一位的,只有三个是两位的,所以在此只存除了声母和单韵母以外的部分
char b[]="qwrtyopssdfghjkkllzxxcvbnm";
char d[10];
map<string,string> m;
map<string,string>::iterator it;
int main()
{
string str0,str1;
char c,cc;
int i,l,sss;
for(i=0;i<26;i++)
{
str0=a[i];
str1=b[i];
m[str0]=str1;
}
while(~scanf("%[a-z]%c",d,&c))
{
sss=l=strlen(d);
if(l==1)//单字母情况
printf("%s%s",d,d);
else if(l==2)//双字母情况
printf("%s",d);
else
{
if(d[1]=='h')//声母是两位的时候分这三种情况
{
if(d[0]=='c')
cc='i';
else if(d[0]=='s')
cc='u';
else if(d[0]=='z')
cc='v';
sss-=2;
str0.assign(d+2);
}
else
{
cc=d[0];str1=d;
for(it=m.begin();it!=m.end();it++)
if((*it).first==str1)//拼音只有韵母的情况 韵母str0 就是整个拼音
{
str0.assign(d);break;
}
if(it==m.end())//表里找不到和拼音一样的,说明有声母,因为上面已经处理过两位声母的情况,所以下面是一个声母的情况
{
sss-=1;
str0.assign(d+1);//此时 韵母str0 就是除了第一个声母以外的部分
}
}
printf("%c",cc);//声母部分翻译的字符
if(sss==1)//韵母部分是一位的情况
printf("%c",d[l-1]);
else
cout<<m[str0];
}
printf("%c",c);
}
return 0;
}