A. Romaji

题目链接

Codeforces Round #497 (Div. 2)--A. Romaji

题解

简单题。字符串基础题。判断给定的字符串是否满足所有除了n之外的辅音字母后是否都有元婴字母。
直接跑一遍判断即可。

代码

#include<iostream>
#include<string>
#include<string.h>
using namespace std;
string s;
int main()
{
    cin >> s;
    for (int i = 0; i < s.length() - 1; i++) {
        if (!(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'n')) {
            if (!(s[i + 1] == 'a' || s[i + 1] == 'e' || s[i + 1] == 'i' || s[i + 1] == 'o' || s[i + 1] == 'u')) {
                cout << "NO";
                return 0;
            }
        }
    }
    if (!(s[s.length() - 1] == 'a' || s[s.length() - 1] == 'e' || s[s.length() - 1] == 'i' || s[s.length() - 1] == 'o' || s[s.length() - 1] == 'u' || s[s.length() - 1] == 'n'))cout << "NO";
    else cout << "YES";
    return 0;
}

标签: implementation, strings

添加新评论