跳到正文

题解

题解:P13593 [NWRRC 2023] Missing Vowels

#SUSPENDED#约 3 分钟
原文
文章信息与版本

文章信息

发布
2025年8月7日
收录
2025年12月12日
更新
2026年11月16日
篇幅
约 3 分钟
题目
P13593

版本

  1. v1当前

题目传送门


声明:此题需要使用字符串,请先学习此知识点。

废话不少说,咱们书归正题。为了方便比较字符串 ss 和 ff,先全部转为小写,随后建立两个指针 ii(指向 ss ),jj(指向 ff )。 而现在就需要处理两种情况:

1.如果是辅音,则必须与 s[i]s\left[i\right] 匹配,然后 ii 和 jj 都加 11。

2.如果是元音,选择跳过(不匹配),此时 jj 加 11,ii 不变。


后面就超级简单了,same 和 different 一目了然。

AC code:

C++
#include <iostream>
#include <string>
#include <cctype> 

using namespace std;

bool isVowel(char c) {//看是不是元音
    c = tolower(c);
    return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y';
}

int main() {
    string s, f;
    getline(cin, s);
    getline(cin, f);

    int i = 0; 
    int j = 0; 
    int len_s = s.length();//记录长度
    int len_f = f.length();

    while (i < len_s && j < len_f) {//情况判断
        if (tolower(s[i]) == tolower(f[j])) {
            i++;
            j++;
        } else {
            if (isVowel(f[j])) {
                j++;
            } else {
                cout << "Different" << endl;//代表多出来一个辅音 直接kill
                return 0;
            }
        }
    }

    while (j < len_f) {
        if (!isVowel(f[j])) {
            cout << "Different" << endl;//同理 直接double kill
            return 0;
        }
        j++;
    }

    if (i == len_s) {
        cout << "Same" << endl;
    } else {
        cout << "Different" << endl;//
    }

    return 0;
}

甚至代码里都没出现判断辅音和 - ,简单至极!

原文