-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_10757.java
More file actions
62 lines (50 loc) ยท 1.99 KB
/
_10757.java
File metadata and controls
62 lines (50 loc) ยท 1.99 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package backjoon;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;
// https://www.acmicpc.net/problem/10757
// ํฐ ์ A+B
public class _10757 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
//sol 1 memory 12124 runtime 140
/*
String str_A = st.nextToken();
String str_B = st.nextToken();
// ๋ ๊ฐ์ ์ ์ค ๊ฐ์ฅ ๊ธด ์๋ฆฌ์ ๊ธธ์ด๋ฅผ ๊ตฌํด๋
int max_length = Math.max(str_A.length(), str_B.length());
int[] A = new int[max_length + 1]; // ๋ง์ง๋ง ์๋ฆฌ์ ์ฌ๋ฆผ์ด ์์ ์ ์์ผ๋ฏ๋ก +1
int[] B = new int[max_length + 1]; // ๋ง์ง๋ง ์๋ฆฌ์ ์ฌ๋ฆผ์ด ์์ ์ ์์ผ๋ฏ๋ก +1
// A ๋งจ ๋ค ๋ฌธ์๋ถํฐ ์ญ์์ผ๋ก ํ๋์ฉ ์ ์ฅ
for(int i = str_A.length() - 1, idx = 0; i >= 0; i--, idx++) {
A[idx] = str_A.charAt(i) - '0';
}
// B ๋งจ ๋ค ๋ฌธ์๋ถํฐ ์ญ์์ผ๋ก ํ๋์ฉ ์ ์ฅ
for(int i = str_B.length() - 1, idx = 0; i >= 0; i--, idx++) {
B[idx] = str_B.charAt(i) - '0';
}
for(int i = 0; i < max_length; i++) {
int value = A[i] + B[i];
A[i] = value % 10; // ๋ํ ๊ฐ์ 10์ผ๋ก ๋๋ ๋๋จธ์ง๊ฐ ์๋ฆฌ๊ฐ์ด ๋จ
A[i + 1] += (value / 10); // ๋ํ ๊ฐ์ 10์ผ๋ก ๋๋ ๋ชซ์ด ์ฌ๋ฆผ๊ฐ์ด ๋จ
}
// A๋ฐฐ์ด ์ญ์ ์ถ๋ ฅ
// ๊ฐ์ฅ ๋์ ์๋ฆฌ์๊ฐ 0์ผ ์๋ ์๊ธฐ ๋๋ฌธ์ 0์ด ์๋ ๊ฒฝ์ฐ์๋ง ์ถ๋ ฅ
StringBuilder sb = new StringBuilder();
if(A[max_length] != 0) {
sb.append(A[max_length]);
}
for(int i = max_length - 1; i >= 0; i--) {
sb.append(A[i]);
}
System.out.println(sb);
*/
//sol2 memory 15052 runtime 192
BigInteger A = new BigInteger(st.nextToken());
BigInteger B = new BigInteger(st.nextToken());
System.out.println(A.add(B));
}
}