[BaekJoon] #5063 - TGN [Java][C++][Python]
[BaekJoon] #5063 - TGN [Java][C++][Python]
1. 아이디어
광고를 해야 하는지 판정하는 문제로, 광고를 했을 때의 수익 $e$에서 광고 비용 $c$를 빼야 실제 수익이므로 $e - c$를 광고하지 않았을 때의 수익 $r$과 비교한다.
2. 코드
풀이 [Java][C++][Python]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
while (n-- > 0) {
StringTokenizer st = new StringTokenizer(br.readLine());
int r = Integer.parseInt(st.nextToken());
int e = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
if (r > e - c) {
bw.write("do not advertise\n");
} else if (r < e - c) {
bw.write("advertise\n");
} else {
bw.write("does not matter\n");
}
}
bw.flush();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
while (n--) {
int r, e, c;
cin >> r >> e >> c;
if (r > e - c) {
cout << "do not advertise\n";
} else if (r < e - c) {
cout << "advertise\n";
} else {
cout << "does not matter\n";
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
import sys
input = sys.stdin.readline
n = int(input())
for _ in range(n):
r, e, c = map(int, input().split())
if r > e - c:
print("do not advertise")
elif r < e - c:
print("advertise")
else:
print("does not matter")
This post is licensed under CC BY 4.0 by the author.