Untitled
Someunknown
java
3 years ago
1.2 kB
6
Indexable
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
List<Integer> list1 = new ArrayList<>();
List<Integer> list2 = new ArrayList<>();
List<Integer> list3 = new ArrayList<>();
int n = scanner.nextInt();
int m = scanner.nextInt();
while(n-- > 0) {
int x = scanner.nextInt();
list1.add(x);
}
while(m-- > 0) {
int x = scanner.nextInt();
list2.add(x);
}
int x1 = 0;
int x2 = 0;
int carry = 0;
while (x1 < list1.size() || x2 < list2.size() || carry != 0) {
int x = (x1 < list1.size()) ? list1.get(x1) : 0;
int y = (x2 < list2.size()) ? list2.get(x2) : 0;
int sum = carry + x + y;
carry = sum / 10;
list3.add(sum % 10);
if (x1 < list1.size())
x1++;
if (x2 < list2.size())
x2++;
}
for (Integer integer : list3) {
System.out.print(integer + " ");
}
}
}Editor is loading...