Diff
checker
文本
文本
图像
文档
Excel
文件夹
Legal
Enterprise
桌面版
定价
登录
下载 Diffchecker 桌面版
比较文本
查找两个文本文件之间的差异
工具
历史
实时编辑器
折叠未更改行
关闭换行
视图
拆分
统一
比对精度
智能
单词
字符
语法高亮
选择语法
忽略
文本转换
转到第一个差异
编辑输入
Diffchecker Desktop
运行Diffchecker最安全的方式。获取Diffchecker桌面应用:您的差异永远不会离开您的电脑!
获取桌面版
Untitled diff
创建于
11年前
差异永不过期
清除
导出
分享
解释
8 删除
行
总计
删除
字符
总计
删除
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
215 行
全部复制
0 添加
行
总计
添加
字符
总计
添加
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
210 行
全部复制
import java.io.*;
import java.io.*;
import java.util.*;
import java.util.*;
import java.math.*;
import java.math.*;
public class TicTac implements Runnable {
public class TicTac implements Runnable {
private static BufferedReader in;
private static BufferedReader in;
private static PrintWriter out;
private static PrintWriter out;
private static StringTokenizer st;
private static StringTokenizer st;
private static Random rnd;
private static Random rnd;
static class Pair {
static class Pair {
final int x, y;
final int x, y;
public Pair(int x, int y) {
public Pair(int x, int y) {
this.x = x;
this.x = x;
this.y = y;
this.y = y;
}
}
}
}
private void solve() throws IOException {
private void solve() throws IOException {
while (true) {
while (true) {
char[][] field = readField();
char[][] field = readField();
if (isOver(field))
if (isOver(field))
break;
break;
if (!isEmpty(field))
if (!isEmpty(field))
throw new AssertionError();
throw new AssertionError();
field[1][1] = 'x';
field[1][1] = 'x';
printField(field);
printField(field);
field = readField();
field = readField();
Pair corner = selectCorner(field);
Pair corner = selectCorner(field);
field[corner.x][corner.y] = 'x';
field[corner.x][corner.y] = 'x';
printField(field);
printField(field);
field = readField();
field = readField();
Pair opposite = new Pair(2 - corner.x, 2 - corner.y);
Pair opposite = new Pair(2 - corner.x, 2 - corner.y);
if (field[opposite.x][opposite.y] == '.') {
if (field[opposite.x][opposite.y] == '.') {
field[opposite.x][opposite.y] = 'x';
field[opposite.x][opposite.y] = 'x';
printField(field);
printField(field);
continue;
continue;
}
}
Pair support = selectSupport(field);
Pair support = selectSupport(field);
field[support.x][support.y] = 'x';
field[support.x][support.y] = 'x';
printField(field);
printField(field);
field = readField();
field = readField();
Pair last = selectLast(field);
Pair last = selectLast(field);
field[last.x][last.y] = 'x';
field[last.x][last.y] = 'x';
printField(field);
printField(field);
}
}
}
}
private boolean isEmpty(char[][] field) {
private boolean isEmpty(char[][] field) {
for (int i = 0; i <= 2; i++)
for (int i = 0; i <= 2; i++)
for (int j = 0; j <= 2; j++)
for (int j = 0; j <= 2; j++)
if (field[i][j] != '.')
if (field[i][j] != '.')
return false;
return false;
return true;
return true;
}
}
private Pair selectLast(char[][] field) {
private Pair selectLast(char[][] field) {
for (int x0 = 0; x0 <= 2; x0++) {
for (int x0 = 0; x0 <= 2; x0++) {
for (int y0 = 0; y0 <= 2; y0++) {
for (int y0 = 0; y0 <= 2; y0++) {
for (int x1 = 0; x1 <= 2; x1++) {
for (int x1 = 0; x1 <= 2; x1++) {
for (int y1 = 0; y1 <= 2; y1++) {
for (int y1 = 0; y1 <= 2; y1++) {
int dx = x1 - x0;
int dx = x1 - x0;
int dy = y1 - y0;
int dy = y1 - y0;
if (Math.abs(dx) + Math.abs(dy) == 0)
if (Math.abs(dx) + Math.abs(dy) == 0)
continue;
continue;
if (Math.abs(dx) > 1 || Math.abs(dy) > 1)
if (Math.abs(dx) > 1 || Math.abs(dy) > 1)
continue;
continue;
if (field[x0][y0] != 'x')
if (field[x0][y0] != 'x')
continue;
continue;
if (field[x1][y1] != 'x')
if (field[x1][y1] != 'x')
continue;
continue;
int x2 = x1 + dx, y2 = y1 + dy;
int x2 = x1 + dx, y2 = y1 + dy;
if (x2 >= 0 && x2 <= 2 && y2 >= 0 && y2 <= 2 && field[x2][y2] == '.') {
if (x2 >= 0 && x2 <= 2 && y2 >= 0 && y2 <= 2 && field[x2][y2] == '.') {
return new Pair(x2, y2);
return new Pair(x2, y2);
}
}
}
}
}
}
}
}
}
}
throw new AssertionError();
throw new AssertionError();
}
}
private Pair selectSupport(char[][] field) {
private Pair selectSupport(char[][] field) {
for (int x = 0; x <= 2; x++) {
for (int x = 0; x <= 2; x++) {
for (int y = 0; y <= 2; y++) {
for (int y = 0; y <= 2; y++) {
if ((x + y) % 2 == 1 && field[x][y] == '.') {
if ((x + y) % 2 == 1 && field[x][y] == '.') {
field[x][y] = 'x';
field[x][y] = 'x';
int ways = calcWays(field);
int ways = calcWays(field);
if (ways >= 2) {
if (ways >= 2) {
return new Pair(x, y);
return new Pair(x, y);
}
}
field[x][y] = '.';
field[x][y] = '.';
}
}
}
}
}
}
throw new AssertionError();
throw new AssertionError();
}
}
private int calcWays(char[][] field) {
private int calcWays(char[][] field) {
boolean[][] used = new boolean[3][3];
boolean[][] used = new boolean[3][3];
for (int x0 = 0; x0 <= 2; x0++) {
for (int x0 = 0; x0 <= 2; x0++) {
for (int y0 = 0; y0 <= 2; y0++) {
for (int y0 = 0; y0 <= 2; y0++) {
for (int x1 = 0; x1 <= 2; x1++) {
for (int x1 = 0; x1 <= 2; x1++) {
for (int y1 = 0; y1 <= 2; y1++) {
for (int y1 = 0; y1 <= 2; y1++) {
int dx = x1 - x0;
int dx = x1 - x0;
int dy = y1 - y0;
int dy = y1 - y0;
if (Math.abs(dx) + Math.abs(dy) == 0)
if (Math.abs(dx) + Math.abs(dy) == 0)
continue;
continue;
if (Math.abs(dx) > 1 || Math.abs(dy) > 1)
if (Math.abs(dx) > 1 || Math.abs(dy) > 1)
continue;
continue;
if (field[x0][y0] != 'x')
if (field[x0][y0] != 'x')
continue;
continue;
if (field[x1][y1] != 'x')
if (field[x1][y1] != 'x')
continue;
continue;
int x2 = x1 + dx, y2 = y1 + dy;
int x2 = x1 + dx, y2 = y1 + dy;
if (x2 >= 0 && x2 <= 2 && y2 >= 0 && y2 <= 2 && field[x2][y2] == '.') {
if (x2 >= 0 && x2 <= 2 && y2 >= 0 && y2 <= 2 && field[x2][y2] == '.') {
used[x2][y2] = true;
used[x2][y2] = true;
}
}
}
}
}
}
}
}
}
}
int res = 0;
int res = 0;
for (int i = 0; i <= 2; i++)
for (int i = 0; i <= 2; i++)
for (int j = 0; j <= 2; j++)
for (int j = 0; j <= 2; j++)
if (used[i][j])
if (used[i][j])
++res;
++res;
return res;
return res;
}
}
private Pair selectCorner(char[][] field) {
private Pair selectCorner(char[][] field) {
int[] xs = { 0, 2 }, ys = { 0, 2 };
int[] xs = { 0, 2 }, ys = { 0, 2 };
for (int x : xs)
for (int x : xs)
for (int y : ys) {
for (int y : ys) {
if (field[x][y] == '.')
if (field[x][y] == '.')
return new Pair(x, y);
return new Pair(x, y);
}
}
throw new AssertionError();
throw new AssertionError();
}
}
private void printField(char[][] field) {
private void printField(char[][] field) {
for (int i = 0; i < 3; i++)
for (int i = 0; i < 3; i++)
out.println(new String(field[i]));
out.println(new String(field[i]));
out.flush();
out.flush();
}
}
private char[][] readField() throws IOException {
private char[][] readField() throws IOException {
char[][] result = new char[3][];
char[][] result = new char[3][];
for (int i = 0; i < 3; i++)
for (int i = 0; i < 3; i++)
result[i] = nextToken().toCharArray();
result[i] = nextToken().toCharArray();
return result;
return result;
}
}
private boolean isOver(char[][] field) {
private boolean isOver(char[][] field) {
for (int i = 0; i <= 2; i++)
for (int i = 0; i <= 2; i++)
for (int j = 0; j <= 2; j++)
for (int j = 0; j <= 2; j++)
if (field[i][j] != 'x')
if (field[i][j] != 'x')
return false;
return false;
return true;
return true;
}
}
public static void main(String[] args) {
public static void main(String[] args) {
new TicTac().run();
new TicTac().run();
}
}
public void run() {
public void run() {
final String className = this.getClass().getName().toLowerCase();
final String className = this.getClass().getName().toLowerCase();
try {
try {
复制
已复制
复制
已复制
try {
in = new BufferedReader(new InputStreamReader(System.in));
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter(System.out);
out = new PrintWriter(new FileWriter("output.txt"));
} catch (FileNotFoundException e) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
rnd = new Random();
rnd = new Random();
solve();
solve();
out.close();
out.close();
} catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
e.printStackTrace();
System.exit(1);
System.exit(1);
}
}
}
}
private String nextToken() throws IOException {
private String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
while (st == null || !st.hasMoreTokens()) {
String line = in.readLine();
String line = in.readLine();
if (line == null)
if (line == null)
return null;
return null;
st = new StringTokenizer(line);
st = new StringTokenizer(line);
}
}
return st.nextToken();
return st.nextToken();
}
}
private int nextInt() throws IOException {
private int nextInt() throws IOException {
return Integer.parseInt(nextToken());
return Integer.parseInt(nextToken());
}
}
private long nextLong() throws IOException {
private long nextLong() throws IOException {
return Long.parseLong(nextToken());
return Long.parseLong(nextToken());
}
}
private double nextDouble() throws IOException {
private double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
return Double.parseDouble(nextToken());
}
}
}
}
已保存差异
原始文本
打开文件
import java.io.*; import java.util.*; import java.math.*; public class TicTac implements Runnable { private static BufferedReader in; private static PrintWriter out; private static StringTokenizer st; private static Random rnd; static class Pair { final int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } private void solve() throws IOException { while (true) { char[][] field = readField(); if (isOver(field)) break; if (!isEmpty(field)) throw new AssertionError(); field[1][1] = 'x'; printField(field); field = readField(); Pair corner = selectCorner(field); field[corner.x][corner.y] = 'x'; printField(field); field = readField(); Pair opposite = new Pair(2 - corner.x, 2 - corner.y); if (field[opposite.x][opposite.y] == '.') { field[opposite.x][opposite.y] = 'x'; printField(field); continue; } Pair support = selectSupport(field); field[support.x][support.y] = 'x'; printField(field); field = readField(); Pair last = selectLast(field); field[last.x][last.y] = 'x'; printField(field); } } private boolean isEmpty(char[][] field) { for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) if (field[i][j] != '.') return false; return true; } private Pair selectLast(char[][] field) { for (int x0 = 0; x0 <= 2; x0++) { for (int y0 = 0; y0 <= 2; y0++) { for (int x1 = 0; x1 <= 2; x1++) { for (int y1 = 0; y1 <= 2; y1++) { int dx = x1 - x0; int dy = y1 - y0; if (Math.abs(dx) + Math.abs(dy) == 0) continue; if (Math.abs(dx) > 1 || Math.abs(dy) > 1) continue; if (field[x0][y0] != 'x') continue; if (field[x1][y1] != 'x') continue; int x2 = x1 + dx, y2 = y1 + dy; if (x2 >= 0 && x2 <= 2 && y2 >= 0 && y2 <= 2 && field[x2][y2] == '.') { return new Pair(x2, y2); } } } } } throw new AssertionError(); } private Pair selectSupport(char[][] field) { for (int x = 0; x <= 2; x++) { for (int y = 0; y <= 2; y++) { if ((x + y) % 2 == 1 && field[x][y] == '.') { field[x][y] = 'x'; int ways = calcWays(field); if (ways >= 2) { return new Pair(x, y); } field[x][y] = '.'; } } } throw new AssertionError(); } private int calcWays(char[][] field) { boolean[][] used = new boolean[3][3]; for (int x0 = 0; x0 <= 2; x0++) { for (int y0 = 0; y0 <= 2; y0++) { for (int x1 = 0; x1 <= 2; x1++) { for (int y1 = 0; y1 <= 2; y1++) { int dx = x1 - x0; int dy = y1 - y0; if (Math.abs(dx) + Math.abs(dy) == 0) continue; if (Math.abs(dx) > 1 || Math.abs(dy) > 1) continue; if (field[x0][y0] != 'x') continue; if (field[x1][y1] != 'x') continue; int x2 = x1 + dx, y2 = y1 + dy; if (x2 >= 0 && x2 <= 2 && y2 >= 0 && y2 <= 2 && field[x2][y2] == '.') { used[x2][y2] = true; } } } } } int res = 0; for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) if (used[i][j]) ++res; return res; } private Pair selectCorner(char[][] field) { int[] xs = { 0, 2 }, ys = { 0, 2 }; for (int x : xs) for (int y : ys) { if (field[x][y] == '.') return new Pair(x, y); } throw new AssertionError(); } private void printField(char[][] field) { for (int i = 0; i < 3; i++) out.println(new String(field[i])); out.flush(); } private char[][] readField() throws IOException { char[][] result = new char[3][]; for (int i = 0; i < 3; i++) result[i] = nextToken().toCharArray(); return result; } private boolean isOver(char[][] field) { for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) if (field[i][j] != 'x') return false; return true; } public static void main(String[] args) { new TicTac().run(); } public void run() { final String className = this.getClass().getName().toLowerCase(); try { try { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter(new FileWriter("output.txt")); } catch (FileNotFoundException e) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } rnd = new Random(); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } private String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { String line = in.readLine(); if (line == null) return null; st = new StringTokenizer(line); } return st.nextToken(); } private int nextInt() throws IOException { return Integer.parseInt(nextToken()); } private long nextLong() throws IOException { return Long.parseLong(nextToken()); } private double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } }
更改后文本
打开文件
import java.io.*; import java.util.*; import java.math.*; public class TicTac implements Runnable { private static BufferedReader in; private static PrintWriter out; private static StringTokenizer st; private static Random rnd; static class Pair { final int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } private void solve() throws IOException { while (true) { char[][] field = readField(); if (isOver(field)) break; if (!isEmpty(field)) throw new AssertionError(); field[1][1] = 'x'; printField(field); field = readField(); Pair corner = selectCorner(field); field[corner.x][corner.y] = 'x'; printField(field); field = readField(); Pair opposite = new Pair(2 - corner.x, 2 - corner.y); if (field[opposite.x][opposite.y] == '.') { field[opposite.x][opposite.y] = 'x'; printField(field); continue; } Pair support = selectSupport(field); field[support.x][support.y] = 'x'; printField(field); field = readField(); Pair last = selectLast(field); field[last.x][last.y] = 'x'; printField(field); } } private boolean isEmpty(char[][] field) { for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) if (field[i][j] != '.') return false; return true; } private Pair selectLast(char[][] field) { for (int x0 = 0; x0 <= 2; x0++) { for (int y0 = 0; y0 <= 2; y0++) { for (int x1 = 0; x1 <= 2; x1++) { for (int y1 = 0; y1 <= 2; y1++) { int dx = x1 - x0; int dy = y1 - y0; if (Math.abs(dx) + Math.abs(dy) == 0) continue; if (Math.abs(dx) > 1 || Math.abs(dy) > 1) continue; if (field[x0][y0] != 'x') continue; if (field[x1][y1] != 'x') continue; int x2 = x1 + dx, y2 = y1 + dy; if (x2 >= 0 && x2 <= 2 && y2 >= 0 && y2 <= 2 && field[x2][y2] == '.') { return new Pair(x2, y2); } } } } } throw new AssertionError(); } private Pair selectSupport(char[][] field) { for (int x = 0; x <= 2; x++) { for (int y = 0; y <= 2; y++) { if ((x + y) % 2 == 1 && field[x][y] == '.') { field[x][y] = 'x'; int ways = calcWays(field); if (ways >= 2) { return new Pair(x, y); } field[x][y] = '.'; } } } throw new AssertionError(); } private int calcWays(char[][] field) { boolean[][] used = new boolean[3][3]; for (int x0 = 0; x0 <= 2; x0++) { for (int y0 = 0; y0 <= 2; y0++) { for (int x1 = 0; x1 <= 2; x1++) { for (int y1 = 0; y1 <= 2; y1++) { int dx = x1 - x0; int dy = y1 - y0; if (Math.abs(dx) + Math.abs(dy) == 0) continue; if (Math.abs(dx) > 1 || Math.abs(dy) > 1) continue; if (field[x0][y0] != 'x') continue; if (field[x1][y1] != 'x') continue; int x2 = x1 + dx, y2 = y1 + dy; if (x2 >= 0 && x2 <= 2 && y2 >= 0 && y2 <= 2 && field[x2][y2] == '.') { used[x2][y2] = true; } } } } } int res = 0; for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) if (used[i][j]) ++res; return res; } private Pair selectCorner(char[][] field) { int[] xs = { 0, 2 }, ys = { 0, 2 }; for (int x : xs) for (int y : ys) { if (field[x][y] == '.') return new Pair(x, y); } throw new AssertionError(); } private void printField(char[][] field) { for (int i = 0; i < 3; i++) out.println(new String(field[i])); out.flush(); } private char[][] readField() throws IOException { char[][] result = new char[3][]; for (int i = 0; i < 3; i++) result[i] = nextToken().toCharArray(); return result; } private boolean isOver(char[][] field) { for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) if (field[i][j] != 'x') return false; return true; } public static void main(String[] args) { new TicTac().run(); } public void run() { final String className = this.getClass().getName().toLowerCase(); try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); rnd = new Random(); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } private String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { String line = in.readLine(); if (line == null) return null; st = new StringTokenizer(line); } return st.nextToken(); } private int nextInt() throws IOException { return Integer.parseInt(nextToken()); } private long nextLong() throws IOException { return Long.parseLong(nextToken()); } private double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } }
查找差异