[백준] Baekjoon Online Judge
문제
King Dragon, the king of Animal Kingdom, passed away this morning. This unfortunate news saddened every animal. Since no one sees any other living dragon nowadays, the government of Animal Kingdom cannot find any successor to King Dragon. But Animal Kingdom cannot operate without a king. The government of Animal Kingdom decided to elect a new king.
There are nine voters: Armadillo, Buffalo, Cat, Dog, Elephant, Fox, Goat, Hippo and Zebra and two candidates: Tiger and Lion.
The votes will be anonymously casted tomorrow. The government asked you to write a program to calculate the votes and announce the next king of Animal Kingdom. Note that the next king is the one who receives more than half the votes.
입력
The input has exactly nine lines. Each of them is a string which is either Tiger or Lion, and it represents a casted vote from an anonymous voter.
출력
Output one line containing the next king’s name.
제한
- Every string in the input is either Tiger or Lion.
- The next king must be qualified by at least five votes.
풀이
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tiger = 0;
for (int i = 0; i < 9; i++) {
string s;
cin >> s;
if (s == "Tiger") tiger++;
}
if (tiger >= 5) cout << "Tiger\n";
else cout << "Lion\n";
return 0;
}
Tiger을 입력 받은 횟수가 5 이상이라면 Tiger를 출력하고, 아니라면 Lion을 출력한다.
'백준 > C++' 카테고리의 다른 글
[Baekjoon/C++] 12789번 - 도키도키 간식드리미 (1) | 2024.12.26 |
---|---|
[Baekjoon/C++] 28278번 - 스택 2 (0) | 2024.12.22 |
[Baekjoon/C++] 32775번 - 가희와 4시간의 벽 1 (0) | 2024.12.10 |
[Baekjoon/C++] 31306번 - Is Y a Vowel? (0) | 2024.12.08 |
[Baekjoon/C++] 16946번 - 벽 부수고 이동하기 4 (0) | 2024.12.07 |