※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 17598번 문제인 Animal King Election이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/17598 

 

17598번: Animal King Election

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 Kingdo

www.acmicpc.net

주어지는 9개의 문자열 중 "Lion"이 더 많은지 "Tiger"이 더 많은지를 세 더 많이 등장한 동물을 출력하는 문제이다.

 

이는 반복문을 이용한 구현으로 간단히 해결할 수 있다.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <string>
using namespace std;

int L, T;

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

	for (int i = 0; i < 9; i++) {
		string s; cin >> s;
		if (s[0] == 'L') L++;
		else T++;
	}
	if (L < T) cout << "Tiger";
	else cout << "Lion";
}
728x90

+ Recent posts