본문 바로가기

백준/C++

[Baekjoon/C++] 31306번 - Is Y a Vowel?

[백준] Baekjoon Online Judge

문제로 이동

 

문제

The Vowels are a, e, i, o and u, and possibly y. People disagree on whether y is a vowel or not. Unfortunately for you, you have been tasked with counting the number of vowels in a word. You'll have to count how many vowels there are assuming y is a vowel, and assuming y is not.

 

입력

The single line of input contains a string of at least one and at most 50 lowercase letters.

 

출력

Output two space-separated integers. The first is the number of vowels assuming y is not a vowel, the second is the number of vowels assuming y is a vowel.

 


풀이

#include <iostream>
using namespace std;

char mo[6] = { 'a', 'e', 'i', 'o', 'u', 'y' };

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string s;
    cin >> s;

    int cnt = 0;
    int yCnt = 0;

    for (int i = 0; i < s.length(); i++) {
        for (char c : mo) {
            if (s[i] == c) {
                if (c == 'y') yCnt++;
                cnt++;

                break;
            }
        }
    }

    cout << cnt - yCnt << ' ' << cnt << '\n';

    return 0;
}