forked from MiYazJE/Acepta-el-reto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp124.java
34 lines (27 loc) · 1.04 KB
/
p124.java
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
import java.util.Scanner;
public class p124 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String str1, str2;
int[] n1, n2;
while (true) {
str1 = s.next();
str2 = s.next();
if (str1.equals("0") && str2.equals("0"))
break;
n1 = new int[Math.max(str1.length(), str2.length())];
n2 = new int[Math.max(str1.length(), str2.length())];
for (int i = 0; i < str1.length(); i++) n1[i] = Integer.parseInt(str1.charAt(str1.length() - 1 - i) + "");
for (int i = 0; i < str2.length(); i++) n2[i] = Integer.parseInt(str2.charAt(str2.length() - 1 - i) + "");
int ans = 0, carry = 0;
for (int i = 0; i < n1.length; i++) {
if ((n1[i] + n2[i] + carry) >= 10) {
ans++;
carry = (n1[i]+ n2[i] + carry) / 10;
}
else carry = 0;
}
System.out.println( ans );
}
}
}