[BaekJoon] #11382 - 꼬마 정민 [Java][C++]
[BaekJoon] #11382 - 꼬마 정민 [Java][C++]
1. 아이디어
세 정수 $A$, $B$, $C$의 합을 구하는 문제로 각 수의 최댓값이 $10^{12}$까지여서 정수 타입을 사용할 경우 오버플로우에 주의해야 한다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(1)$ | $O(1)$ |
3. 코드
풀이 [Java][C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 = new StringTokenizer(br.readLine());
long a = Long.parseLong(st.nextToken());
long b = Long.parseLong(st.nextToken());
long c = Long.parseLong(st.nextToken());
System.out.println(a + b + c);
}
}
1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long a, b, c;
cin >> a >> b >> c;
cout << a + b + c;
}
This post is licensed under CC BY 4.0 by the author.