codeforces 解题报告 1008A. Romaji 字符串模拟

http://codeforces.com/problemset/problem/1008/A

吐槽:真是毒瘤DIV2场,我一个pupil打了三题才+1分




解题思路:

1.遍历字符串,找出双辅音或者辅音结尾就返回NO,找不到就表示串满足条件返回YES

2.注意字符 'n' 特殊处理,它后面可以接任何字符或不接字符,遍历时直接跳过即可

3.公告添加样例:nz   和   king

4.我学过日文罗马音的人觉得 'n' 有点像汉语拼音的后鼻音 


import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        boolean tag = true;                   //false表示串尾是辅音或串中出现双辅音(字符'n'特殊处理)
        for(int i = 0;i < str.length();i++) {
            if(str.charAt(i) == 'n')
                continue;
            if (str.charAt(i) != 'a' && str.charAt(i) != 'e'&& str.charAt(i) != 'o'&& str.charAt(i) != 'i' && str.charAt(i) != 'u') {
                //辅音为串尾
                if (i + 1 >= str.length()) {
                    tag = false;
                    break;
                }
                //双辅音
                if (str.charAt(i + 1) != 'a' && str.charAt(i + 1) != 'e'&& str.charAt(i + 1) != 'o'&& str.charAt(i + 1) != 'i' && str.charAt(i + 1) != 'u') {
                    tag = false;
                    break;
                }
            }
        }
        if(tag == false) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    }
}

猜你喜欢

转载自blog.csdn.net/a912952381/article/details/81040122
今日推荐