[BaekJoon] 5596번 - 시험 점수 [Java][C++]
[BaekJoon] 5596번 - 시험 점수 [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
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));
StringTokenizer st;
int sum1 = 0;
st = new StringTokenizer(br.readLine());
while (st.hasMoreTokens()) {
sum1 += Integer.parseInt(st.nextToken());
}
int sum2 = 0;
st = new StringTokenizer(br.readLine());
while (st.hasMoreTokens()) {
sum2 += Integer.parseInt(st.nextToken());
}
System.out.println(Math.max(sum1, sum2));
}
}
2. 풀이 [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 sum1 = 0;
for (int i = 0; i < 4; i++) {
int x;
cin >> x;
sum1 += x;
}
int sum2 = 0;
for (int i = 0; i < 4; i++) {
int x;
cin >> x;
sum2 += x;
}
cout << max(sum1, sum2);
}
This post is licensed under CC BY 4.0 by the author.