[백준 5063] TGN (C#, C++) - soo:bak
작성일 :
문제 링크
설명
여러 개의 광고 효과 분석 데이터가 주어지는 상황에서, N (1 ≤ N ≤ 20)개의 테스트 케이스와 각 케이스마다 세 정수 r, e, c (-10^6 ≤ r, e ≤ 10^6, 0 ≤ c ≤ 10^6)가 주어질 때, 광고를 할지 말지 결정하는 문제입니다.
- r: 광고를 하지 않았을 때의 수익
- e: 광고를 했을 때의 수익
- c: 광고 비용
광고를 했을 때의 순이익(e - c)이 광고를 하지 않았을 때의 수익(r)보다 크면 “advertise”, 같으면 “does not matter”, 작으면 “do not advertise”를 출력합니다.
접근법
광고를 했을 때의 실제 순이익은 광고 수익에서 광고 비용을 뺀 값입니다.
이 순이익을 광고를 하지 않았을 때의 수익과 비교하여 어느 쪽이 더 유리한지 판단합니다.
세 가지 경우로 나누어 적절한 메시지를 출력하면 됩니다.
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()!);
for (var i = 0; i < n; i++) {
var input = Array.ConvertAll(Console.ReadLine()!.Split(), int.Parse);
var noAdProfit = input[0];
var adRevenue = input[1];
var adCost = input[2];
var adProfit = adRevenue - adCost;
if (adProfit > noAdProfit) Console.WriteLine("advertise");
else if (adProfit == noAdProfit) Console.WriteLine("does not matter");
else Console.WriteLine("do not advertise");
}
}
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
while (n--) {
int noAdProfit, adRevenue, adCost;
cin >> noAdProfit >> adRevenue >> adCost;
int adProfit = adRevenue - adCost;
if (adProfit > noAdProfit) cout << "advertise\n";
else if (adProfit == noAdProfit) cout << "does not matter\n";
else cout << "do not advertise\n";
}
return 0;
}