-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountingSticks.java
More file actions
53 lines (51 loc) · 1.12 KB
/
CountingSticks.java
File metadata and controls
53 lines (51 loc) · 1.12 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
package codeforces;
import java.util.*;
public class CountingSticks {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
String input = sc.next();
char in[] = input.toCharArray();
int a = 0, b = 0, c = 0;
boolean f1=true,f2=false,f3=false;
for(char ch : in){
if(f1 && ch!='+' && ch!='=' && ch=='|'){
a++;
}else if(ch=='+'){
f1 = false;
f2 = true;
continue;
}else if(f2 && ch!='=' && ch=='|'){
b++;
}else if(ch=='='){
f2 = false;
f3 = true;
continue;
}else if(f3 && ch=='|'){
c++;
}else{
break;
}
}
if((a+b)==c){
System.out.println(input);
}else if((a+b-1)==c+1){
if(a>1){
System.out.println(input.substring(1)+"|");
}else{
System.out.println(input.replace("|=", "=|"));
}
}else if((a+b+1)==c-1){
if(c>1){
System.out.println("|"+input.substring(0,input.length()-1));
}else{
System.out.println(input.replace("=|", "|="));
}
}else{
System.out.println("Impossible");
}
}
}