YJ/C++

[백준/BOJ/C++] 11319번 Count Me In

Team DAON 2021. 11. 9. 16:14

[문제]

Given a sentence in English, output the counts of consonants and vowels.

Vowels are letters in [’A’,’E’,’I’,’O’,’U’,’a’,’e’,’i’,’o’,’u’].

[입력]

The test file starts with an integer S(1 ≤ S ≤ 100), the number of sentences.

Then follow S lines, each containing a sentence - words of length 1 to 20 separated by spaces. Every sentence will contain at least one word and be comprised only of characters [a-z][A-Z] and spaces. No sentence will be longer than 1000 characters.

[출력]

For each sentence, output the number of consonants and vowels on a line, separated by space.

[Source Code]

#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int num;
	cin >> num;
	cin.ignore();

	for(int i = 0; i < num; i++){
		int con = 0, vow = 0;
		string input;
		getline(cin, input);
		for(int j = 0; j < input.length(); j++){
			if(input[j] == 'A' || input[j] == 'a' ||
				input[j] == 'E' || input[j] == 'e' ||
				input[j] == 'I' || input[j] == 'i' ||
				input[j] == 'O' || input[j] == 'o' ||
				input[j] == 'U' || input[j] == 'u')
				vow++;
			else if(input[j] != ' ')
				con++;
		}

		cout << con << " " << vow << "\n";
	}
}

[결과 화면]