반응형
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
간단 구현 문제였습니다.
📕 풀이방법
📔 입력 및 초기화
문자열 s, a점수 b점수 a,b를 선언 후 적절히 입력받습니다.
📔 풀이과정
짝수 index만 확인해 해당 팀의 각 참가자가 얻은 점수를 조건에 맞춰 a, b에 더해줍니다.
📔 정답출력
a가 이겼다면 'A'를 아니라면 'B'를 출력해줍니다.
📕 Code
#include <bits/stdc++.h>
using namespace std;
string s;
int a, b;
int main(){
cin >> s;
for(int i = 0; i < s.size(); i+=2){
if(s[i] == 'A') a += s[i+1] - '0';
else b += s[i+1] - '0';
}
if(a > b) cout << "A";
else cout << "B";
}
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Implementation' 카테고리의 다른 글
(C++) - 백준(BOJ) 3578 : Holes (0) | 2022.07.07 |
---|---|
(C++) - 백준(BOJ) 11257 : IT Passport Examination (0) | 2022.07.06 |
(C++) - 백준(BOJ) 25311 : UCPC에서 가장 쉬운 문제 번호는? (0) | 2022.07.04 |
(C++) - 백준(BOJ) 25314 : 코딩은 체육과목 입니다. (0) | 2022.07.03 |
(C++) - 백준(BOJ) 3733 : Shares (0) | 2022.07.03 |