[백준 17009] Winning Score (C#, C++) - soo:bak
작성일 :
문제 링크
설명
농구 경기에서 Apples 팀과 Bananas 팀 각각의 득점 기록이 3점슛, 2점슛, 1점슛의 성공 횟수 순서로 주어집니다.
이 때, 두 팀의 총점을 비교하여 더 높은 팀을 출력하는 문제입니다.
접근법
각 팀마다 3개 값을 순서대로 입력받아 각각 3, 2, 1을 곱한 후 합산하여 총점을 구합니다.
Apples 팀과 Bananas 팀 모두 동일한 방식으로 계산합니다.
두 팀의 총점을 비교하여 Apples가 더 높으면 A, Bananas가 더 높으면 B, 동점이면 T를 출력합니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
namespace Solution {
class Program {
static void Main(string[] args) {
var apples = 0;
for (var points = 3; points >= 1; points--)
apples += int.Parse(Console.ReadLine()!) * points;
var bananas = 0;
for (var points = 3; points >= 1; points--)
bananas += int.Parse(Console.ReadLine()!) * points;
if (apples > bananas) Console.WriteLine("A");
else if (apples < bananas) Console.WriteLine("B");
else Console.WriteLine("T");
}
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int apples = 0, bananas = 0;
for (int p = 3; p >= 1; --p) {
int cnt; cin >> cnt;
apples += cnt * p;
}
for (int p = 3; p >= 1; --p) {
int cnt; cin >> cnt;
bananas += cnt * p;
}
if (apples > bananas) cout << "A\n";
else if (apples < bananas) cout << "B\n";
else cout << "T\n";
return 0;
}