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()); } }
尋找差異