본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 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

간단 구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

문자열 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";
}

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.