-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 60.txt
More file actions
52 lines (49 loc) · 1.63 KB
/
Day 60.txt
File metadata and controls
52 lines (49 loc) · 1.63 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
import java.util.*;
class Main
{
static String checkFlood(String str)
{
Stack<Character> parenthesis = new Stack<>();
for(int i=0;i<str.length();i++)
{
switch(str.charAt(i))
{
case '(':
case '<':
case '{':
case '[':
parenthesis.push(str.charAt(i));break;
case ')': if(parenthesis.empty() || parenthesis.peek()!='(')
return "Flood";
else
parenthesis.pop();
break;
case '>': if(parenthesis.empty() || parenthesis.peek()!='<')
return "Flood";
else
parenthesis.pop();
break;
case '}': if(parenthesis.empty() || parenthesis.peek()!='{')
return "Flood";
else
parenthesis.pop();
break;
case ']': if(parenthesis.empty() || parenthesis.peek()!='[')
return "Flood";
else
parenthesis.pop();
break;
}
}
if(parenthesis.empty())
return "No Flood";
else
return "Flood";
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
System.out.println(checkFlood(str));
}
}