b474簡單

母音編號

運用固定字元映射,正確求解本題並處理邊界情況。

解題思路

建立母音 a、e、i、o、u 到1、2、3、4、5的對應。

每個位置獨立查表,母音換成數字,其餘保留原字母,按原順序串接。每個字元只決定自己的輸出,不影響後面位置。

時間 O(|S|),輸入及結果 O(|S|)。

Step-by-step animation

教學例子:教學單字 code,c不是母音。

回報動畫錯誤
步驟 1 / 3

步驟 1

教學單字 code,c不是母音。

c
狀態
c

Reference solution

回報程式錯誤

完整程式

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s, vo = "aeiou";
    cin >> s;
    for (char &c : s) {
        auto p = vo.find(c);
        if (p != string::npos)
            c = '1' + p;
    }
    cout << s << '\n';
}

先試著自己完成,再切換語言比對解法。參考程式可複製到題目編輯器。

更多