-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA 394 - Counting Sticks.java
More file actions
58 lines (48 loc) · 1.41 KB
/
A 394 - Counting Sticks.java
File metadata and controls
58 lines (48 loc) · 1.41 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x = input.nextLine();
int a = 0,b = 0,c = 0;
for (int i = 0; i < x.length(); i++) {
if(x.charAt(i) == '|'){
a++;
}else if(x.charAt(i) == '+'){
b = a;
}else if(x.charAt(i) == '='){
c = a-b;
}
}
a = a -b -c;
if(a < b+c){
a++;
b--;
}else if (a> b + c){
a--;
b++;
}
if(a != b + c){
System.out.println("Impossible");
}else if(a == b+c){
if(b == 0){
c--;
b++;
}else if(c == 0){
c++;
b--;
}
for (int i = 0; i <= a+b+c +1; i++) {
if(i < b)
System.out.print("|");
else if(i == b)
System.out.print("+");
else if(i<=b+c)
System.out.print("|");
else if(i == b + c + 1)
System.out.print("=");
else if(i > b+c)
System.out.print("|");
}
}
}
}