-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11507 - Bender B. Rodríguez Problem
102 lines (90 loc) · 2.35 KB
/
11507 - Bender B. Rodríguez Problem
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer(" ");
}
/** get next word */
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
// TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static String nextLine() throws IOException {
return reader.readLine();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
}
public class Main {
static Map<String, String> map;
static {
map = new HashMap<String, String>();
// positive values
map.put("+x +y", "+y");
map.put("+x -y", "-y");
map.put("+x +z", "+z");
map.put("+x -z", "-z");
map.put("+y +z", "+y");
map.put("+y -z", "+y");
map.put("+y +y", "-x");
map.put("+y -y", "+x");
map.put("+z -y", "+z");
map.put("+z +y", "+z");
map.put("+z +z", "-x");
map.put("+z -z", "+x");
// negative values
map.put("-x +y", "-y");
map.put("-x -y", "+y");
map.put("-x +z", "-z");
map.put("-x -z", "+z");
map.put("-y +z", "-y");
map.put("-y -z", "-y");
map.put("-y +y", "+x");
map.put("-y -y", "-x");
map.put("-z -y", "-z");
map.put("-z +y", "-z");
map.put("-z +z", "+x");
map.put("-z -z", "-x");
}
public static void main(String[] args) throws Exception {
Reader.init(System.in);
int x = -1;
String init = "+x";
String reader = "";
String arr[] = null;
StringBuffer sb = new StringBuffer();
while ((x = Reader.nextInt()) != 0) {
init = "+x";
--x;
arr = new String[x];
reader = Reader.nextLine();
//System.out.println(reader);
arr = reader.split(" ");
for(int i=0;i<arr.length;i++){
if(!arr[i].equals("No"))
init = map.get(init + " " +arr[i]);
}
sb.append(init + "\n");
}
System.out.print(sb.toString());
}
}