井字游戏

This commit is contained in:
James 2020-05-16 10:34:42 +08:00
parent e7be40d15e
commit 912f21ab99
9 changed files with 157 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# 标题
* 内容

View File

@ -0,0 +1 @@
#

Binary file not shown.

123
4096_gamejingzi/main.cpp Normal file
View File

@ -0,0 +1,123 @@
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int a[3][3] = { 0 };
string s[3];
bool cunzai[27] = { 0 }, win[27][27] = { 0 };
int dui[10] = { 0 };
int chang = 0;
for (int i = 0; i < 3; i++) {
cin >> s[i];
for (int j = 0; j < 3; j++) {
int now = s[i][j] - 'A' + 1;
a[i][j] = now;
if (cunzai[now] != 1) {
cunzai[now] = 1;
dui[++chang] = now;
}
}
}
// for(int i=0;i<3;i++){
// for(int j=0;j<3;j++){
// cout<<a[i][j]<<" ";
// }
// cout<<endl;
// }
int ans = 0, dan = 0;
for (int i = 0; i < 3; i++) {
if (a[i][0] == a[i][1] && a[i][1] == a[i][2]) {
// cout<<i<<endl;
if (win[a[i][0]][a[i][0]] == 0) {
win[a[i][0]][a[i][0]] = 1;
dan++;
}
} else {
if (a[i][0] == a[i][1] || a[i][1] == a[i][2]) {
if (win[a[i][0]][a[i][2]] == 0 && win[a[i][2]][a[i][0]] == 0) {
ans++;
win[a[i][0]][a[i][2]] = 1;
}
} else {
if (a[i][0] == a[i][2]) {
if (win[a[i][0]][a[i][1]] == 0 && win[a[i][1]][a[i][0]] == 0) {
ans++;
win[a[i][0]][a[i][1]] = 1;
}
}
}
}
}
for (int i = 0; i < 3; i++) {
if (a[0][i] == a[1][i] && a[1][i] == a[2][i]) {
if (win[a[0][i]][a[0][i]] == 0) {
win[a[0][i]][a[0][i]] = 1;
dan++;
}
} else {
if (a[0][i] == a[1][i] || a[1][i] == a[2][i]) {
if (win[a[0][i]][a[2][i]] == 0 && win[a[2][i]][a[0][i]] == 0) {
ans++;
win[a[0][i]][a[2][i]] = 1;
}
} else {
if (a[0][i] == a[2][i]) {
if (win[a[0][i]][a[1][i]] == 0 && win[a[1][i]][a[0][i]] == 0) {
ans++;
win[a[0][i]][a[1][i]] = 1;
}
}
}
}
}
int tou = a[0][0], zhong = a[1][1], wei = a[2][2];
if (tou == zhong && tou == wei) {
if (win[tou][tou] == 0) {
win[tou][tou] = 1;
dan++;
}
} else {
if (tou == zhong || zhong == wei) {
if (win[tou][wei] == 0 && win[wei][tou] == 0) {
win[tou][wei] = 1;
ans++;
}
} else {
if (tou == wei) {
if (win[tou][zhong] == 0 && win[zhong][wei] == 0) {
win[tou][zhong] == 1;
ans++;
}
}
}
}
tou = a[2][0], wei = a[0][2];
if (tou == zhong && tou == wei) {
if (win[tou][tou] == 0) {
win[tou][tou] = 1;
dan++;
}
} else {
if (tou == zhong || zhong == wei) {
if (win[tou][wei] == 0 && win[wei][tou] == 0) {
win[tou][wei] = 1;
ans++;
}
} else {
if (tou == wei) {
if (win[tou][zhong] == 0 && win[zhong][wei] == 0) {
win[tou][zhong] == 1;
ans++;
}
}
}
}
cout << dan << endl;
cout << ans;
}

BIN
4096_gamejingzi/main.exe Normal file

Binary file not shown.

View File

@ -0,0 +1,3 @@
COW
XXO
ABC

View File

@ -0,0 +1,3 @@
RRR
RRR
RRR

View File

@ -0,0 +1,3 @@
XYZ
XYZ
XYX

View File

@ -0,0 +1,21 @@
## z:\Chao\src\4096_gamejingzi\test\in.txt
2020/05/16 ÖÜÁù 10:26:06.06
0
2
-----------------------------------------------
Process exited after 120 ms with return value 0
## z:\Chao\src\4096_gamejingzi\test\in2.txt
2020/05/16 ÖÜÁù 10:26:06.06
1
0
-----------------------------------------------
Process exited after 80 ms with return value 0
## z:\Chao\src\4096_gamejingzi\test\in3.txt
2020/05/16 ÖÜÁù 10:26:06.06
2
2
-----------------------------------------------
Process exited after 90 ms with return value 0