-
Notifications
You must be signed in to change notification settings - Fork 0
/
A.java
66 lines (55 loc) · 1.22 KB
/
A.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
/*
// Problem: https://open.kattis.com/contests/naq19open/problems/circuitmath
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
HashMap<Character, Boolean> bools = new HashMap<>();
// build map for char - boolean pairs
for (int i = 0; i < n; i++)
{
if (in.next().charAt(0) == 'T')
bools.put((char)((int)'A' + i) , true);
else
bools.put((char)((int)'A' + i) , false);
}
Stack<Boolean> s = new Stack<>();
while(in.hasNext())
{
char c = in.next().charAt(0);
if (Character.isAlphabetic(c))
{
s.push(bools.get(c));
}
else
{
if (c == '*')
{
boolean a = s.pop();
boolean b = s.pop();
s.push(a && b);
}
if (c == '+')
{
boolean a = s.pop();
boolean b = s.pop();
s.push(a || b);
}
if (c == '-')
{
boolean a = s.pop();
s.push((!a));
}
}
if (c == '!')
break;
}
if (s.pop)
System.out.println("T");
else
System.out.println("F");
in.close();
}
}
*/