1 条题解
-
1
嘉然今天吃什么 (Sans) LV 6 @ 2022-8-28 19:41:14
思路
模拟整个下棋过程,下一次判断一次
代码
// // Created by Sans on 2022/8/28. // #include <iostream> using namespace std; #define c2i(x) int((x) - 48) string pos; int cb[3][3], result; int check() { bool t; //行 for (auto &i: cb) { t = i[0] == i[1] && i[1] == i[2]; if (t) { if (i[0] == 1) return 1; else if (i[0] == 2) return 2; } } //列 for (int i = 0; i < 3; i++) { t = cb[0][i] == cb[1][i] && cb[2][i] == cb[0][i]; if (t) { if (cb[0][i] == 1) return 1; else if (cb[0][i] == 2) return 2; } } //对角线 t = cb[0][0] == cb[1][1] && cb[2][2] == cb[0][0]; int t2 = cb[0][2] == cb[1][1] && cb[2][0] == cb[0][2]; if (t || t2) { if (cb[1][1] == 1) return 1; else if (cb[1][1] == 2) return 2; } return 0; } void spilt() { bool turn = false; for (char po: pos) { int x = c2i(po) / 3, y = c2i(po) % 3 - 1; //将数字转换为行和列 if (turn) cb[x][y] = 2; else cb[x][y] = 1; turn = !turn; result = check(); if (result == 1) { cout << "xiaoa wins."; return; } else if (result == 2) { cout << "uim wins."; return; } } cout << "drew."; } int main() { cin >> pos; spilt(); return 0; }
- 1
信息
- ID
- 61
- 时间
- 1000ms
- 内存
- 64MiB
- 难度
- 3
- 标签
- 递交数
- 59
- 已通过
- 4
- 上传者