拼音魔法
Time limit per test: 1.0 seconds
Time limit all tests: 1.0 seconds
Memory limit: 256 megabytes
魔法学校小学一年级有一种题。就是给一个字的拼音,给一个声调,让你正确地注音。但魔法老师给了巨量的题,你不用魔法根本不可能做完。所以现在要让你发明一种魔法完成这个任务。
问题已经讲完了,下面开始教授汉语。(会汉语或者自认为会汉语的可以自动跳过)
汉语中一个字的拼音由声母和韵母两部分组成,在极少数情况下也会没有声母,但一定有韵母。
一般认为,声母有 b, p, m, f, d, t, l, n, g, k, h, j, q, x, z, c, s, zh, ch, sh, r, y, w;韵母有:a, e, o, i, u, ü, ai, ei, ui, ao, ou, iu, ie, üe, er, an, en, in, un, ün, ang, eng, ing, ong。
不是所有的字母都能组合的,组合的时候有时会发生一些神奇的事情,例如 üe 变成了 ue。但是标调规则有如下口诀:
有 a 先找 a,没 a 找 o e,i u 并排标在后,这样标调不会错。
只有下面列出的元素可能会被标调。请按照下表输出(尤其注意 a 不要输出成 ɑ 了):
- 第一声:ā ē ī ō ū ǖ。
- 第二声:á é í ó ú ǘ。
- 第三声:ǎ ě ǐ ǒ ǔ ǚ。
- 第四声:à è ì ò ù ǜ。
- 轻声:a e i o u ü。
辅助材料:由教育部公布的拼音方案。如果有描述不一致的地方,请以本题描述为准。
Input
第一行一个整数 T (1≤T≤105) 。
下面
T
行,每行一个拼音:拼音声调在各个拼音之后,用数字 [1-4] 进行表示。例如 zhong1 guo2
。没有数字的说明是轻声,不用标调。
按照国际惯例,输入文件全部由 ASCII 编码组成。ü
用 v
来代替。但在输出中,应仍然用 ü
来表示。
Output
对于每一组数据,输出 Case x: y
。其中 x 是从 1 开始的测试数据编号,y 是一个拼音标调后的答案。
注意:对于非 ASCII 字符的输出,请使用 UTF-8 编码。
Examples
5 zhong1 guo2 me que1 nv3
Case 1: zhōng Case 2: guó Case 3: me Case 4: quē Case 5: nǚ
Note
会 C/C++ 的魔法师最可爱了。
Source
2017 华东师范大学网赛
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <bitset>
#include <set>
#include <vector>
#include <functional>
using namespace std;
#define LL long long
const int INF = 0x3f3f3f3f;
string s[6][6]={{"ā","ē","ī","ō","ū","ǖ"},{"á","é","í","ó","ú","ǘ"},{"ǎ","ě","ǐ","ǒ","ǔ","ǚ"},{"à","è","ì","ò","ù","ǜ"},{"a","e","i","o","u","ü"}};
char ch[1000];
int main()
{
int t,cas=0;
scanf("%d",&t);
while(t--)
{
printf("Case %d: ",++cas);
scanf("%s",ch);
int len=strlen(ch);
if(ch[len-1]<'1'||ch[len-1]>'4')
{
int p=len;
for(int i=len-1;i>=0;i--)
if(ch[i]=='v') {p=i;break;}
for(int i=0;i<p;i++) printf("%c",ch[i]);
if(p!=len) cout<<s[4][5];
for(int i=p+1;i<len;i++) printf("%c",ch[i]);
printf("\n");
continue;
}
int k=ch[len-1]-'0',p=-1,flag=0;
for(int i=len-1;i>=0;i--)
if(ch[i]=='a') {p=i;break;}
if(p!=-1)
{
for(int i=0;i<p;i++) printf("%c",ch[i]);
cout<<s[k-1][0];
for(int i=p+1;i<len-1;i++) printf("%c",ch[i]);
printf("\n");
continue;
}
for(int i=len-1;i>=0;i--)
if(ch[i]=='o') {p=i;break;}
if(p!=-1)
{
for(int i=0;i<p;i++) printf("%c",ch[i]);
cout<<s[k-1][3];
for(int i=p+1;i<len-1;i++) printf("%c",ch[i]);
printf("\n");
continue;
}
for(int i=len-1;i>=0;i--)
if(ch[i]=='e') {p=i;break;}
if(p!=-1)
{
for(int i=0;i<p;i++) printf("%c",ch[i]);
cout<<s[k-1][1];
for(int i=p+1;i<len-1;i++) printf("%c",ch[i]);
printf("\n");
continue;
}
for(int i=len-1;i>=0;i--)
{
if(ch[i]=='i') {p=i;flag=1;break;}
if(ch[i]=='u') {p=i;flag=2;break;}
}
if(p!=-1)
{
for(int i=0;i<p;i++) printf("%c",ch[i]);
if(flag==1) cout<<s[k-1][2];
else cout<<s[k-1][4];
for(int i=p+1;i<len-1;i++) printf("%c",ch[i]);
printf("\n");
continue;
}
for(int i=0;i<len;i++)
if(ch[i]=='v') {p=i;break;}
for(int i=0;i<p;i++) printf("%c",ch[i]);
cout<<s[k-1][5];
for(int i=p+1;i<len-1;i++) printf("%c",ch[i]);
printf("\n");
}
return 0;
}