POJ 2996 Help Me with the Game && POJ 2993 Emag eht htiw Em Pleh
来源:互联网 发布:js中换行符是哪个 编辑:程序博客网 时间:2024/05/01 09:33
题目1:http://acm.pku.edu.cn/JudgeOnline/problem?id=2996
题目2:http://acm.pku.edu.cn/JudgeOnline/problem?id=2993
画图题,好怀念。它和2993是一对反题,一个是读图一个是画图,很有意思啊。
读图:
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.List;
- public class Main {
- class Compara implements Comparator<String[]> {
- public int compare(String[] o1, String[] o2) {
- if (o1[1].charAt(1) == o2[1].charAt(1)) {
- return o1[1].charAt(0) - o2[1].charAt(0);
- } else if (Character.isUpperCase(o1[0].charAt(0))) {
- return o1[1].charAt(1) - o2[1].charAt(1);
- } else {
- return o2[1].charAt(1) - o1[1].charAt(1);
- }
- }
- }
- static char[] a = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
- public static void main(String[] args) throws IOException {
- BufferedReader read = new BufferedReader(new InputStreamReader(
- System.in));
- String s;
- char c;
- String[] q;
- List<String[]> list = new ArrayList<String[]>();
- String[] t;
- for (int i = 0; i < 17; i++) {
- if (i % 2 == 0) {
- read.readLine();
- continue;
- }
- s = read.readLine();
- q = s.split("//|");
- for (int j = 1; j <= 8; j++) {
- c = q[j].charAt(1);
- if (c == '.' || c == ':') {
- continue;
- }
- t = new String[2];
- t[0] = "" + c;
- t[1] = "" + a[j - 1] + (8 - i / 2);
- list.add(t);
- }
- }
- System.out.print("White: ");
- print("K", list);
- print("Q", list);
- print("R", list);
- print("B", list);
- print("N", list);
- print("P", list);
- System.out.println();
- System.out.print("Black: ");
- print("k", list);
- print("q", list);
- print("r", list);
- print("b", list);
- print("n", list);
- print("p", list);
- System.out.println();
- }
- public static void print(String key, List<String[]> list) {
- if (key.equals("k") || key.equals("K") || key.equals("q")
- || key.equals("Q")) {
- String[] s = null;
- for (int i = 0; i < list.size(); i++) {
- s = list.get(i);
- if (s[0].equals(key)) {
- break;
- }
- }
- if (s != null) {
- if (key.equals("k") || key.equals("K")) {
- System.out.print(Character.toUpperCase(key.charAt(0))
- + s[1]);
- } else {
- System.out.print("," + Character.toUpperCase(key.charAt(0))
- + s[1]);
- }
- }
- } else {
- List<String[]> temp = new ArrayList<String[]>();
- String[] s;
- for (int i = 0; i < list.size(); i++) {
- s = list.get(i);
- if (s[0].equals(key)) {
- temp.add(s);
- }
- }
- if (temp.size() > 0) {
- Collections.sort(temp, new Main().new Compara());
- if (key.equals("p") || key.equals("P")) {
- for (int i = 0; i < temp.size(); i++) {
- System.out.print("," + temp.get(i)[1]);
- }
- } else {
- for (int i = 0; i < temp.size(); i++) {
- System.out.print(","
- + Character.toUpperCase(key.charAt(0))
- + temp.get(i)[1]);
- }
- }
- }
- }
- }
- }
画图:
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Arrays;
- public class Main {
- static char[] a = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
- public static void main(String[] args) throws IOException {
- BufferedReader read = new BufferedReader(new InputStreamReader(
- System.in));
- String white = read.readLine();
- String black = read.readLine();
- white = white.substring(7);
- black = black.substring(7);
- String[] w = white.split("//,");
- String[] b = black.split("//,");
- char[][] c = new char[17][33];
- int flg = 1;
- for (int i = 0; i < 17; i++) {
- for (int j = 0; j < 33; j++) {
- if (i % 2 == 0) {
- if (j % 4 == 0) {
- c[i][j] = '+';
- } else {
- c[i][j] = '-';
- }
- } else {
- if (j % 4 == 0) {
- c[i][j] = '|';
- } else {
- if (flg == 1) {
- c[i][j] = '.';
- c[i][j + 1] = '.';
- c[i][j + 2] = '.';
- } else {
- c[i][j] = ':';
- c[i][j + 1] = ':';
- c[i][j + 2] = ':';
- }
- flg *= -1;
- j += 2;
- }
- }
- }
- if (i % 2 != 0) {
- flg *= -1;
- }
- }
- for (int i = 0; i < w.length; i++) {
- String s = w[i];
- if (s.length() == 3) {
- char key = s.charAt(0);
- char col = s.charAt(1);
- char row = s.charAt(2);
- int ic = Arrays.binarySearch(a, col);
- ic = 2 + 4 * ic;
- int ir = 8 - (row - '0');
- ir = 1 + 2 * ir;
- c[ir][ic] = key;
- } else {
- char col = s.charAt(0);
- char row = s.charAt(1);
- int ic = Arrays.binarySearch(a, col);
- ic = 2 + 4 * ic;
- int ir = 8 - (row - '0');
- ir = 1 + 2 * ir;
- c[ir][ic] = 'P';
- }
- }
- for (int i = 0; i < b.length; i++) {
- String s = b[i];
- if (s.length() == 3) {
- char key = s.charAt(0);
- char col = s.charAt(1);
- char row = s.charAt(2);
- int ic = Arrays.binarySearch(a, col);
- ic = 2 + 4 * ic;
- int ir = 8 - (row - '0');
- ir = 1 + 2 * ir;
- c[ir][ic] = Character.toLowerCase(key);
- } else {
- char col = s.charAt(0);
- char row = s.charAt(1);
- int ic = Arrays.binarySearch(a, col);
- ic = 2 + 4 * ic;
- int ir = 8 - (row - '0');
- ir = 1 + 2 * ir;
- c[ir][ic] = 'p';
- }
- }
- for (int i = 0; i < 17; i++) {
- for (int j = 0; j < 33; j++) {
- System.out.print(c[i][j]);
- }
- System.out.println();
- }
- }
- }
- POJ 2996 Help Me with the Game && POJ 2993 Emag eht htiw Em Pleh
- poj-2993-Emag eht htiw Em Pleh && poj-2996-Help Me with the Game
- Poj 2993 Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- POJ 2993 Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- Poj 2993 Emag eht htiw Em Pleh
- POJ 2993:Emag eht htiw Em Pleh
- Emag eht htiw Em Pleh(POJ--2993
- poj 2993 Emag eht htiw Em Pleh
- POJ 2993 - Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- POJ-2993-Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- POJ-2993-Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh(关联2996)
- j2me中socket的开发
- 管理软件到底有没有前途(三)-从国家十一五信息化战略规划来看
- php调用web service
- Tomcat+Axis实现webservice
- 数组指针和指针数组
- POJ 2996 Help Me with the Game && POJ 2993 Emag eht htiw Em Pleh
- 补水养生的14个惊人真相
- 修改时间
- Firefox在含有flash的网页上提示:不建议使用 getBoxObjectFor() 。 请使用 element.getBoundingClientRect()。
- 简单的加密与解密
- 如何教学?
- 使用Js来让IE支持png图片透明效果
- DirectX 3D 基本框架(三)
- [BF]身世