코딩로그
[백준/BOJ/C++] 11319번 Count Me In 본문
[문제]
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";
}
}
[결과 화면]
'YJ > C++' 카테고리의 다른 글
[백준/BOJ/C++] 4388번 받아올림 (0) | 2021.11.09 |
---|---|
[백준/BOJ/C++] 17249번 태보태보 총난타 (0) | 2021.11.09 |
[백준/BOJ/C++] 4613번 Quicksum (0) | 2021.11.09 |
[백준/BOJ/C++] 4597번 패리티 (0) | 2021.11.09 |
[백준/BOJ/C++] 6763번 Speed fines are not fine! (0) | 2021.11.08 |