-
Notifications
You must be signed in to change notification settings - Fork 7
/
Main.java
68 lines (53 loc) · 1.24 KB
/
Main.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
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
63
64
65
66
67
68
package basicLevel1037;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Coin p = new Coin(in.next().split("[.]"));
Coin a = new Coin(in.next().split("[.]"));
in.close();
Coin result = new Coin();
if (p.galleon > a.galleon) {
System.out.print("-");
// p minus a
if (p.kunt < a.kunt) {
p.kunt += 29;
p.sickle--;
}
result.kunt = p.kunt - a.kunt;
if (p.sickle < a.sickle) {
p.sickle += 17;
p.galleon--;
}
result.sickle = p.sickle - a.sickle;
result.galleon = p.galleon - a.galleon;
} else {
// a minus p
if (p.kunt > a.kunt) {
a.kunt += 29;
a.sickle--;
}
result.kunt = a.kunt - p.kunt;
if (p.sickle > a.sickle) {
a.sickle += 17;
a.galleon--;
}
result.sickle = a.sickle - p.sickle;
result.galleon = a.galleon - p.galleon;
}
System.out.print(result.galleon + "." + result.sickle + "." + result.kunt);
}
}
class Coin {
int galleon;
int sickle;
int kunt;
public Coin() {
this.galleon = this.sickle = this.kunt = 0;
}
public Coin(String[] coin) {
this.galleon = Integer.parseInt(coin[0]);
this.sickle = Integer.parseInt(coin[1]);
this.kunt = Integer.parseInt(coin[2]);
}
}