-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathURI1212PrimaryArithmetic.java
More file actions
62 lines (55 loc) · 1.24 KB
/
URI1212PrimaryArithmetic.java
File metadata and controls
62 lines (55 loc) · 1.24 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
/**
* See
* <a href="https://www.urionlinejudge.com.br/judge/en/problems/view/1212">Primary
* Arithmetic</a>
*
* @author Brian Yeicol Restrepo Tangarife
*/
public class URI1212PrimaryArithmetic {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
String l;
String[] P;
int a, b, carries, r, r1, r2;
while (!(l = read()).equals("0 0")) {
P = l.split("\\s");
a = toInt(P[0]);
b = toInt(P[1]);
carries = 0;
r = 0;
while (true) {
r1 = a % 10;
r2 = b % 10;
a /= 10;
b /= 10;
if (r + r1 + r2 > 9) {
r = 1;
carries++;
} else {
r = 0;
}
if(a == 0 && b ==0){
break;
}
}
if (carries > 0) {
out.print(carries + " carry operation");
out.println(carries == 1 ? "." : "s.");
} else {
out.println("No carry operation.");
}
}
out.close();
}
private static String read() throws IOException {
return in.readLine();
}
private static int toInt(String s) {
return Integer.parseInt(s);
}
}