[BaekJoon] 5063번 - TGN [Java][C++]
[BaekJoon] 5063번 - TGN [Java][C++]
1. 문제 풀이
광고를 하지 않았을 때의 수익과 광고를 했을 때 수익에서 광고 비용을 뺀 것을 비교하면 광고를 할지 말지를 판단할 수 있다.
2. 코드
1. 풀이 [Java]
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
28
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));
StringTokenizer st;
int N = Integer.parseInt(br.readLine());
for (int i = 0; i < N; i++) {
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();
}
}
2. 풀이 [C++]
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(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
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";
}
}
}
This post is licensed under CC BY 4.0 by the author.