leetcode-master/problems/kamacoder/0132.夹吃旗.md

48 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 132. 夹吃棋
[题目链接](https://kamacoder.com/problempage.php?pid=1209)
这道题是模拟题,但很多录友可能想复杂了。
行方向,白棋吃,只有这样的布局 `o*o`,黑棋吃,只有这样的布局 `*o*`
列方向也是同理的。
想到这一点,本题的代码就容易写了, C++代码如下:
```CPP
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int black = 0, white = 0;
vector<string> grid(3, "");
// 判断行
for (int i = 0; i < 3; i++) {
cin >> grid[i];
if (grid[i] == "o*o") white++;
if (grid[i] == "*o*") black++;
}
// 判断列
for (int i = 0; i < 3; i++) {
string s;
s += grid[0][i];
s += grid[1][i];
s += grid[2][i];
if (s == "o*o") white++;
if (s == "*o*") black++;
}
// 如果一个棋盘的局面没有一方被夹吃或者黑白双方都被对面夹吃则认为是平局
if ((!white && !black) || (white && black)) cout << "draw" << endl;
// 白棋赢
else if (white && !black) cout << "yukan" << endl;
// 黑棋赢
else cout << "kou" << endl;
}
}
```