Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. import java.io.OutputStream;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.PrintWriter;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7. import java.util.ArrayList;
  8. import java.util.StringTokenizer;
  9. import java.io.BufferedReader;
  10. import java.util.Collections;
  11. import java.io.InputStream;
  12.  
  13. /**
  14. * @author MaxHeap
  15. */
  16. public class scorify {
  17. public static void main(String[] args) {
  18. InputStream inputStream = System.in;
  19. OutputStream outputStream = System.out;
  20. FastReader in = new FastReader(inputStream);
  21. PrintWriter out = new PrintWriter(outputStream);
  22. QuickChallenge40A solver = new QuickChallenge40A();
  23. solver.solve(1, in, out);
  24. out.close();
  25. }
  26.  
  27. static class QuickChallenge40A {
  28. String[] pieces = {"k", "q", "r", "b", "n", "p"};
  29.  
  30. public void solve(int testNumber, FastReader in, PrintWriter out) {
  31. int row = 8, col = 1;
  32.  
  33. ArrayList<QuickChallenge40A.Piece> black = new ArrayList<>();
  34. ArrayList<QuickChallenge40A.Piece> white = new ArrayList<>();
  35.  
  36. for (int i = 0; i < 17; i++) {
  37. String line = in.nextLine();
  38. if (line.startsWith("+")) continue;
  39. String[] splited = line.split("\\|");
  40. int c = 1;
  41.  
  42. for (String str : splited) {
  43. if (str.isEmpty() || str.contains("|")) continue;
  44. if (isPiece(str)) {
  45. if (isBlack(str)) {
  46. //black
  47. black.add(new QuickChallenge40A.Piece(extractPiece(str), row, c, 0));
  48. } else {
  49. white.add(new QuickChallenge40A.Piece(extractPiece(str), row, c, 1));
  50. }
  51. }
  52. c++;
  53. }
  54. --row;
  55. }
  56.  
  57. Collections.sort(white);
  58. Collections.sort(black);
  59.  
  60. StringBuilder whiteS = new StringBuilder("White: ");
  61. StringBuilder blackS = new StringBuilder("Black: ");
  62. for (QuickChallenge40A.Piece p : white) {
  63. whiteS.append(p + ",");
  64. }
  65. for (QuickChallenge40A.Piece p : black) {
  66. blackS.append(p + ",");
  67. }
  68. out.println(whiteS.toString().substring(0, whiteS.length() - 1).trim());
  69. out.println(blackS.toString().substring(0, blackS.length() - 1).trim());
  70. }
  71.  
  72. private boolean isBlack(String str) {
  73. for (String p : pieces) {
  74. if (str.contains(p)) return true;
  75. }
  76. return false;
  77. }
  78.  
  79. private boolean isPiece(String str) {
  80. for (String s : pieces) {
  81. if (str.contains(s) || str.contains(s.toUpperCase())) return true;
  82. }
  83. return false;
  84. }
  85.  
  86. private String extractPiece(String s) {
  87. for (int i = 0; i < s.length(); i++) {
  88. if (isPiece(Character.toString(s.charAt(i)))) return Character.toString(s.charAt(i));
  89. }
  90. return "";
  91. }
  92.  
  93. static class Piece implements Comparable<QuickChallenge40A.Piece> {
  94. int x;
  95. int y;
  96. int color;
  97. String type;
  98.  
  99. public Piece(String type, int x, int y, int color) {
  100. this.type = type;
  101. this.x = x;
  102. this.y = y;
  103. this.color = color;
  104. }
  105.  
  106. public int getRating() {
  107. if (type.equals("K") || type.equals("k")) return 99;
  108. if (type.equals("Q") || type.equals("q")) return 89;
  109. if (type.equals("R") || type.equals("r")) return 79;
  110. if (type.equals("B") || type.equals("b")) return 69;
  111. if (type.equals("N") || type.equals("n")) return 59;
  112. return 1;
  113. }
  114.  
  115.  
  116. public int compareTo(QuickChallenge40A.Piece o) {
  117. int mine = getRating();
  118. int other = o.getRating();
  119. if (mine != other) {
  120. return Integer.compare(other, mine);
  121. }
  122. if (color == 0) {
  123. if (o.x == x) {
  124. return Integer.compare(y, o.y);
  125. }
  126. return Integer.compare(o.x, x);
  127. } else {
  128. if (o.x == x) {
  129. return Integer.compare(y, o.y);
  130. }
  131. return Integer.compare(x, o.x);
  132. }
  133. }
  134.  
  135. public String toString() {
  136. return (type.equals("p") || type.equals("P") ? "" : type.toUpperCase()) + Character.toString((char) (y - 1 + 'a')) + x;
  137. }
  138.  
  139. }
  140.  
  141. }
  142.  
  143. static class FastReader {
  144. BufferedReader reader;
  145. StringTokenizer st;
  146.  
  147. public FastReader(InputStream stream) {
  148. reader = new BufferedReader(new InputStreamReader(stream));
  149. st = null;
  150. }
  151.  
  152. public String nextLine() {
  153. String s = null;
  154. try {
  155. s = reader.readLine();
  156. } catch (IOException e) {
  157. e.printStackTrace();
  158. }
  159. return s;
  160. }
  161.  
  162. }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement