※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 18198번 문제인 Basketball One-on-One이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/18198
18198번: Basketball One-on-One
The input consists of a single line with no more than 200 characters: the record of one game. The record consists of single letters (either A or B) alternating with single numbers (either 1 or 2), and includes no spaces or other extraneous characters. Each
www.acmicpc.net
주어지는 문자열은 지문에 주어진 규칙대로 진행된 농구게임의 득점기록이므로, A와 B가 총 몇 점씩을 얻었는지 구해 그 값을 비교하는 것으로 문제를 해결할 수 있다.
아래 코드의 score과 같은 배열을 이용해 구현을 간단히 할 수도 있다.
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
using namespace std;
string s;
int score[128];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s; int slen = s.length();
for (int i = 0; i < slen; i += 2) {
score[s[i]] += s[i + 1] - '0';
}
if (score['A'] > score['B']) cout << 'A';
else cout << 'B';
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 18698 // C++] The Walking Adam (0) | 2022.10.30 |
---|---|
[BOJ 4696 // C++] St. Ives (0) | 2022.10.30 |
[BOJ 25600 // C++] Triathlon (0) | 2022.10.30 |
[BOJ 25635 // C++] 자유 이용권 (0) | 2022.10.29 |
[BOJ 25644 // C++] 최대 상승 (0) | 2022.10.28 |