[백준 24569] Fergusonball Ratings (C#, C++) - soo:bak
작성일 :
문제 링크
설명
선수마다 점수와 파울이 주어집니다. 별점은 점수에 5를 곱하고 파울에 3을 곱한 값을 뺀 것입니다.
별점이 40을 초과하는 선수의 수를 세고, 모든 선수가 40을 넘으면 골드 팀이므로 출력 끝에 +를 붙이는 문제입니다.
접근법
먼저, 각 선수의 점수와 파울을 입력받아 별점을 계산합니다.
다음으로, 별점이 40을 초과하면 개수를 증가시킵니다.
이후, 개수를 출력하고 개수가 선수 수와 같으면 +를 덧붙입니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
namespace Solution {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine()!);
var cnt = 0;
for (var i = 0; i < n; i++) {
var points = int.Parse(Console.ReadLine()!);
var fouls = int.Parse(Console.ReadLine()!);
var rating = points * 5 - fouls * 3;
if (rating > 40)
cnt++;
}
Console.Write(cnt);
if (cnt == n)
Console.Write("+");
Console.WriteLine();
}
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
int cnt = 0;
for (int i = 0; i < n; i++) {
int points, fouls; cin >> points >> fouls;
int rating = points * 5 - fouls * 3;
if (rating > 40)
cnt++;
}
cout << cnt;
if (cnt == n) cout << "+";
cout << "\n";
return 0;
}