Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.OutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.PrintWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.StringTokenizer;
- import java.io.BufferedReader;
- import java.util.Collections;
- import java.io.InputStream;
- /**
- * @author MaxHeap
- */
- public class scorify {
- public static void main(String[] args) {
- InputStream inputStream = System.in;
- OutputStream outputStream = System.out;
- FastReader in = new FastReader(inputStream);
- PrintWriter out = new PrintWriter(outputStream);
- QuickChallenge40A solver = new QuickChallenge40A();
- solver.solve(1, in, out);
- out.close();
- }
- static class QuickChallenge40A {
- String[] pieces = {"k", "q", "r", "b", "n", "p"};
- public void solve(int testNumber, FastReader in, PrintWriter out) {
- int row = 8, col = 1;
- ArrayList<QuickChallenge40A.Piece> black = new ArrayList<>();
- ArrayList<QuickChallenge40A.Piece> white = new ArrayList<>();
- for (int i = 0; i < 17; i++) {
- String line = in.nextLine();
- if (line.startsWith("+")) continue;
- String[] splited = line.split("\\|");
- int c = 1;
- for (String str : splited) {
- if (str.isEmpty() || str.contains("|")) continue;
- if (isPiece(str)) {
- if (isBlack(str)) {
- //black
- black.add(new QuickChallenge40A.Piece(extractPiece(str), row, c, 0));
- } else {
- white.add(new QuickChallenge40A.Piece(extractPiece(str), row, c, 1));
- }
- }
- c++;
- }
- --row;
- }
- Collections.sort(white);
- Collections.sort(black);
- StringBuilder whiteS = new StringBuilder("White: ");
- StringBuilder blackS = new StringBuilder("Black: ");
- for (QuickChallenge40A.Piece p : white) {
- whiteS.append(p + ",");
- }
- for (QuickChallenge40A.Piece p : black) {
- blackS.append(p + ",");
- }
- out.println(whiteS.toString().substring(0, whiteS.length() - 1).trim());
- out.println(blackS.toString().substring(0, blackS.length() - 1).trim());
- }
- private boolean isBlack(String str) {
- for (String p : pieces) {
- if (str.contains(p)) return true;
- }
- return false;
- }
- private boolean isPiece(String str) {
- for (String s : pieces) {
- if (str.contains(s) || str.contains(s.toUpperCase())) return true;
- }
- return false;
- }
- private String extractPiece(String s) {
- for (int i = 0; i < s.length(); i++) {
- if (isPiece(Character.toString(s.charAt(i)))) return Character.toString(s.charAt(i));
- }
- return "";
- }
- static class Piece implements Comparable<QuickChallenge40A.Piece> {
- int x;
- int y;
- int color;
- String type;
- public Piece(String type, int x, int y, int color) {
- this.type = type;
- this.x = x;
- this.y = y;
- this.color = color;
- }
- public int getRating() {
- if (type.equals("K") || type.equals("k")) return 99;
- if (type.equals("Q") || type.equals("q")) return 89;
- if (type.equals("R") || type.equals("r")) return 79;
- if (type.equals("B") || type.equals("b")) return 69;
- if (type.equals("N") || type.equals("n")) return 59;
- return 1;
- }
- public int compareTo(QuickChallenge40A.Piece o) {
- int mine = getRating();
- int other = o.getRating();
- if (mine != other) {
- return Integer.compare(other, mine);
- }
- if (color == 0) {
- if (o.x == x) {
- return Integer.compare(y, o.y);
- }
- return Integer.compare(o.x, x);
- } else {
- if (o.x == x) {
- return Integer.compare(y, o.y);
- }
- return Integer.compare(x, o.x);
- }
- }
- public String toString() {
- return (type.equals("p") || type.equals("P") ? "" : type.toUpperCase()) + Character.toString((char) (y - 1 + 'a')) + x;
- }
- }
- }
- static class FastReader {
- BufferedReader reader;
- StringTokenizer st;
- public FastReader(InputStream stream) {
- reader = new BufferedReader(new InputStreamReader(stream));
- st = null;
- }
- public String nextLine() {
- String s = null;
- try {
- s = reader.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return s;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement