824. 山羊拉丁文
简单模拟,强调对函数isalpha
和tolower
等字符处理函数的运用
// shiran
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1000000007;
class Solution
{
public:
set<char> S = {'a', 'e', 'i', 'o', 'u'};
string toGoatLatin(string s)
{
string res, post = "a";
rep(i, 0, sz(s))
{
int j = i;
while (j < sz(s) && isalpha(s[j]))
j++;
if (S.count(tolower(s[i])))
{
res += s.substr(i, j - i) + "ma" + post;
}
else
{
res += s.substr(i + 1, j - i - 1) + s[i] + "ma" + post;
}
post += "a";
i = j;
if (i == sz(s)) continue;
res += " ";
}
return res;
}
};