题目传送门

题目大意

给定一个只有五个字母的字符串,拆分成特定的音节并且输出。

解题思路

通过题目可以知道,两种音节分别为 CV\texttt{CV}CVC\texttt{CVC}。两种音节不同在于他们的后缀不同,如果正向搜寻,那么需要分类讨论,正难则反,因此我们可以逆序遍历求解答案。

定义一个 vector 数组,将字母和 . 加入进去,最后翻转输出即可(由于最后一个字符一定是 .,所以从第二个开始遍历)

AC Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Problem: D. Unnatural Language Processing
// Contest: Codeforces - Codeforces Round 918 (Div. 4)
// URL: https://codeforces.com/contest/1915/problem/D
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
// #define int long long
const int INF = 0x3f3f3f3f;

const int N = 2e5 + 9;

char s[N], ans[N];
vector<char> vc;

void solve()
{
vc.clear();
int n; cin >> n;
cin >> s + 1;
for (int i = 1; i <= n; i ++)
{
if (s[i] == 'a' || s[i] == 'e') ans[i] = 'V';
else ans[i] = 'C';
}

/*for (int i = 1; i <= n; i ++) cout << s[i];
cout << '\n';
for (int i = 1; i <= n; i ++) cout << ans[i];
cout << '\n';*/

for (int i = n; i >= 2; i --)
{
if (ans[i] == 'C')
{
vc.push_back(s[i]);
vc.push_back(s[i - 1]);
vc.push_back(s[i - 2]);
vc.push_back('.');
i -= 2;
}
else
{
vc.push_back(s[i]);
vc.push_back(s[i - 1]);
vc.push_back('.');
i --;
}
}
reverse(vc.begin(), vc.end());
for (int i = 1; i < vc.size(); i ++) cout << vc[i];
cout << '\n';
}

signed main()
{
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T; cin >> T;
while (T --) solve();
return 0;
}

以上是丑陋的赛事代码,直接用数组存也可以,仅供参考。