Codeforces-1008A - Romaji------个人题解

一道典型的字符处理题,只要好好读题目就能做出来了。

题目:

Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are “a”, “o”, “u”, “i”, and “e”. Other letters are consonant.

In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant “n”; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words “harakiri”, “yupie”, “man”, and “nbo” are Berlanese while the words “horse”, “king”, “my”, and “nz” are not.

Help Vitya find out if a word s is Berlanese.

输入:

The first line of the input contains the string s consisting of |s| (1≤|s|≤100) lowercase Latin letters.

输出:

Print “YES” (without quotes) if there is a vowel after every consonant except “n”, otherwise print “NO”.

You can print each letter in any case (upper or lower).

范例:

输入:
sumimasen
输出:
YES
输入:
ninja
输出:
YES
输入:
codeforces
输出:
NO

思路:

我们注意到这一题有一个特殊的字母n,它的判定和元音字母几乎一样,但是有一点很重要:

他不能作为元音字母跟在辅音字母后面!!!

一般来说注意到这点就没什么问题了。

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstring>
using namespace std;

int main()
{
	char a[101];
	while (cin.getline(a,101))//输入
	{
		bool err = false;
		int len = strlen(a);
		for (int i = 0; i < len; i++)
		{
			if(i!=len-1)//最后一位前面的字符才有下一位,所以分开判断
				switch (a[i])
				{
				case 'a':
				case 'e':
				case 'i':
				case 'o':
				case 'u':
				case 'n':
					break;
				default:
					if (a[i + 1] != 'a' && a[i + 1] != 'e' && a[i + 1] != 'i' && a[i + 1] != 'o' && a[i + 1] != 'u')
						err = true;//辅音(除了n)后必跟元音字母
					break;
				}
			else switch (a[i])//最后一位,以n以外的辅音字母结尾绝对是非法的
			{
			case 'a':
			case 'e':
			case 'i':
			case 'o':
			case 'u':
			case 'n':
				break;
			default:
				err = true;
				break;
			}
		}
		if (err)
			cout << "NO" << endl;
		else cout << "YES" << endl;//输出
		memset(a, 0, sizeof(a));
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值