※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 26314번 문제인 Vowel Count이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/26314
26314번: Vowel Count
The first input line contains a positive integer, n, indicating the number of names to check. The names are on the following n input lines, one name per line. Each name starts in column 1 and consists of 1-20 lowercase letters (assume the name will not con
www.acmicpc.net
각 주어지는 이름들을 읽어 해당 이름을 구성하는 알파벳 중 자음의 개수와 모음의 개수를 각각 세어주자. 그리고 그 두 값을 비교해 문제의 답으로 0을 출력할지 1을 출력할지를 결정해 문제를 해결하자.
아래와 같이 알파벳을 인덱스로 넣으면 해당 문자가 모음인지를 알 수 있는 배열을 만들면 구현을 단순하게 할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int T;
int vowel[128];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
vowel['a'] = vowel['e'] = vowel['i'] = vowel['o'] = vowel['u'] = 1;
cin >> T;
while (T--) {
int vcnt = 0, ccnt = 0;
string s; cin >> s;
for (auto& l : s) {
if (vowel[l]) vcnt++;
else ccnt++;
}
if (vcnt > ccnt) cout << s << '\n' << 1 << '\n';
else cout << s << '\n' << 0 << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 26392 // C++] Desni klik (0) | 2022.12.14 |
---|---|
[BOJ 24087 // C++] アイスクリーム (Ice Cream) (0) | 2022.12.14 |
[BOJ 11290 // C++] Wonowon (0) | 2022.12.13 |
[BOJ 11287 // C++] Margaret’s Minute Minute Manipulation (0) | 2022.12.13 |
[BOJ 11288 // C++] Ether's Encryption (0) | 2022.12.13 |