题解:P13593 [NWRRC 2023] Missing Vowels

· · 题解

解析见注释。

#include<bits/stdc++.h>
using namespace std;
string l_c(string t); // 将大写字母转化成小写字母
bool check(char c); // 判断一个字母是不是元音字母

string s,f;
int fl;

int main()
{
    cin>>s>>f;
    s=l_c(s),f=l_c(f);
    fl=f.length();
    for(int i=0,j=0;i<f.length();i++,j++) // 逐字校对短、全名
    {
        if(s[j]!=f[i]) // 如果该位置两名不相同
        {
            if(!check(f[i])) // 全名此处不为元音
            {
                cout<<"Different";
                return 0;
            }
            j--,fl--; // 否则跳过(效果等同于删掉)该元音继续校对
        }
        if(s.length()>fl) // 如果短名比长名长
        {
            cout<<"Different";
            return 0;
        }
    }
    cout<<"Same";
    return 0; // 管理大大求过qwq
}
string l_c(string t)
{
    for(int i=0;i<t.length();i++)
        if(t[i]>='A'&&t[i]<='Z')
            t[i]+='a'-'A';
    return t;
}
bool check(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y')
        return 1;
    return 0;
}