algo. quick_sort

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
import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

String str1 = sc.next();
String str2 = sc.next();
int[] num1 = new int[(int)1e5 + 10];
int[] num2 = new int[(int)1e5 + 10];

int len1 = str1.length();
for (int i = len1 - 1; i >= 0; i--) {
num1[len1 - 1 - i] = str1.charAt(i) - '0';
}

int len2 = str2.length();
for (int i = len2 - 1; i >= 0; i--) {
num2[len2 - 1 - i] = str2.charAt(i) - '0';
}

List<Integer> res = add_int(num1, num2, Math.max(len1, len2));
for (int i = 0; i < res.size(); i++) {
System.out.print(res.get(res.size() - 1 - i));
}
}

public static List<Integer> add_int(int[] num1, int[] num2, int len) {
int tmp = 0;
List<Integer> res = new ArrayList(len);
for (int i = 0; i < len; i++) {
int sum = num1[i] + num2[i] + tmp;
res.add(sum % 10);
if (sum >= 10) tmp = 1;
else tmp = 0;
}
if (tmp == 1) res.add(1);
return res;
}
}

algo. quick_sort
http://elwinliu.com/2024/09/08/algo. integer_sum/
Author
Elwin
Posted on
September 8, 2024
Licensed under