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

 

이번에 볼 문제는 백준 13216번 문제인 Badminton이다.
문제는 아래 링크를 확인하자.

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

 

13216번: Badminton

Anisa (Player A) and Ben (Player B) are playing a singles badminton match. Here are the basic badminton rules: To win a match, a player needs to win 2 out of 3 games. The first player to reach 21 points wins the game. (A different rule applies when the pla

www.acmicpc.net

주어지는 배드민턴 경기의 득점순서를 보고, 각 경기를 직접 시뮬레이션을 돌려 문제를 해결하자.

 

각 문자 또한 아스키코드 숫자가 할당되어있다는 점을 이용하여 아래와 같이 배열을 이용해 구현할 수도 있다.

 

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

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

int cnt[128];
int wincnt[128];

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

	string s; cin >> s;
	for (auto& l : s) {
		if (l == 'A') {
			cnt['A']++;
			if (cnt['A'] == 21) {
				cout << cnt['A'] << '-' << cnt['B'] << '\n';
				wincnt['A']++;
				cnt['A'] = cnt['B'] = 0;
			}
		}
		else {
			cnt['B']++;
			if (cnt['B'] == 21) {
				cout << cnt['A'] << '-' << cnt['B'] << '\n';
				wincnt['B']++;
				cnt['A'] = cnt['B'] = 0;
			}
		}
	}

	if (wincnt['A'] == 2) cout << 'A';
	else cout << 'B';
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 13240 // C++] Chessboard  (0) 2022.11.24
[BOJ 20017 // C++] Топот котов  (0) 2022.11.24
[BOJ 10104 // C++] Party Invitation  (0) 2022.11.24
[BOJ 15477 // C++] 水ようかん (Mizuyokan)  (0) 2022.11.24
[BOJ 25400 // C++] 제자리  (0) 2022.11.24

+ Recent posts