import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class kar { BufferedReader rd; kar() throws IOException { rd = new BufferedReader(new InputStreamReader(System.in)); compute(); } private void compute() throws IOException { int t = pint(); StringBuilder buf = new StringBuilder(); for(int i=0;i<t;i++) { if(i > 0) { buf.append('\n'); } buf.append(solve()); } out(buf); } private String solve() throws IOException { int[] q = intarr(); int n = q[0]; int m = q[1]; int[] in = new int[123456]; int[] out = new int[123456]; for(int i=0;i<m;i++) { String[] s = split(rd.readLine()); int v = pint(s[2])-1; if(s[1].charAt(0) == '>') { in[v]++; } else { out[v]++; } } boolean inN = false; boolean out0 = false; for(int i=0;i<n;i++) { if(in[i] == n) { inN = true; break; } if(out[i] == 0) { out0 = true; } } if(inN) { return "WYGRANA"; } if(out0) { return "REMIS"; } return "PRZEGRANA"; } private int pint() throws IOException { return pint(rd.readLine()); } private int pint(String s) { return Integer.parseInt(s); } private int[] intarr() throws IOException { return intarr(rd.readLine()); } private int[] intarr(String s) { String[] q = split(s); int n = q.length; int[] a = new int[n]; for(int i=0;i<n;i++) { a[i] = Integer.parseInt(q[i]); } return a; } private String[] split(String s) { if(s == null) { return new String[0]; } int n = s.length(); int start = -1; int end = 0; int sp = 0; boolean lastWhitespace = true; for(int i=0;i<n;i++) { char c = s.charAt(i); if(isWhitespace(c)) { lastWhitespace = true; } else { if(lastWhitespace) { sp++; } if(start == -1) { start = i; } end = i; lastWhitespace = false; } } if(start == -1) { return new String[0]; } String[] res = new String[sp]; int last = start; int x = 0; lastWhitespace = true; for(int i=start;i<=end;i++) { char c = s.charAt(i); boolean w = isWhitespace(c); if(w && !lastWhitespace) { res[x++] = s.substring(last,i); } else if(!w && lastWhitespace) { last = i; } lastWhitespace = w; } res[x] = s.substring(last,end+1); return res; } private boolean isWhitespace(char c) { return c==' ' || c=='\t'; } private static void out(Object x) { System.out.println(x); } public static void main(String[] args) throws IOException { new kar(); } }
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class kar { BufferedReader rd; kar() throws IOException { rd = new BufferedReader(new InputStreamReader(System.in)); compute(); } private void compute() throws IOException { int t = pint(); StringBuilder buf = new StringBuilder(); for(int i=0;i<t;i++) { if(i > 0) { buf.append('\n'); } buf.append(solve()); } out(buf); } private String solve() throws IOException { int[] q = intarr(); int n = q[0]; int m = q[1]; int[] in = new int[123456]; int[] out = new int[123456]; for(int i=0;i<m;i++) { String[] s = split(rd.readLine()); int v = pint(s[2])-1; if(s[1].charAt(0) == '>') { in[v]++; } else { out[v]++; } } boolean inN = false; boolean out0 = false; for(int i=0;i<n;i++) { if(in[i] == n) { inN = true; break; } if(out[i] == 0) { out0 = true; } } if(inN) { return "WYGRANA"; } if(out0) { return "REMIS"; } return "PRZEGRANA"; } private int pint() throws IOException { return pint(rd.readLine()); } private int pint(String s) { return Integer.parseInt(s); } private int[] intarr() throws IOException { return intarr(rd.readLine()); } private int[] intarr(String s) { String[] q = split(s); int n = q.length; int[] a = new int[n]; for(int i=0;i<n;i++) { a[i] = Integer.parseInt(q[i]); } return a; } private String[] split(String s) { if(s == null) { return new String[0]; } int n = s.length(); int start = -1; int end = 0; int sp = 0; boolean lastWhitespace = true; for(int i=0;i<n;i++) { char c = s.charAt(i); if(isWhitespace(c)) { lastWhitespace = true; } else { if(lastWhitespace) { sp++; } if(start == -1) { start = i; } end = i; lastWhitespace = false; } } if(start == -1) { return new String[0]; } String[] res = new String[sp]; int last = start; int x = 0; lastWhitespace = true; for(int i=start;i<=end;i++) { char c = s.charAt(i); boolean w = isWhitespace(c); if(w && !lastWhitespace) { res[x++] = s.substring(last,i); } else if(!w && lastWhitespace) { last = i; } lastWhitespace = w; } res[x] = s.substring(last,end+1); return res; } private boolean isWhitespace(char c) { return c==' ' || c=='\t'; } private static void out(Object x) { System.out.println(x); } public static void main(String[] args) throws IOException { new kar(); } } |