第一行输入整数
(询问次数)。
每组询问输入
行,每行长度为
的字符串,仅含 ``
``(白子)、``
``(黑子)、``
``(未落子),表示棋盘状态。
对每局输出一行:
小红胜输出 ``
``;
小紫胜输出 ``
``;
平局输出 ``
``。
3 ... o*o ... o** ooo ..* o*o *o* o*o
yukari kou draw
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
scanner.nextLine(); // 消耗换行符
for (int i = 0; i < t; i++) {
// 读取3x3棋盘
char[][] board = new char[3][3];
for (int j = 0; j < 3; j++) {
String line = scanner.nextLine();
board[j] = line.toCharArray();
}
// 判断双方被夹吃的情况
// 小红(黑棋)是否有被夹吃的棋子
boolean redEaten = hasEaten(board, '*');
// 小紫(白棋)是否有被夹吃的棋子
boolean purpleEaten = hasEaten(board, 'o');
// 根据规则判断结果
if (redEaten && !purpleEaten) {
System.out.println("yukari"); // 小紫胜
} else if (!redEaten && purpleEaten) {
System.out.println("kou"); // 小红胜
} else {
System.out.println("draw"); // 平局
}
}
scanner.close();
}
/**
* 检查指定棋子是否有被夹吃的情况
* @param board 棋盘
* @param piece 要检查的棋子('*'或'o')
* @return 是否有被夹吃的棋子
*/
private static boolean hasEaten(char[][] board, char piece) {
char opponent = (piece == '*') ? 'o' : '*';
// 检查横向被夹吃的情况
for (int row = 0; row < 3; row++) {
// 中间是当前棋子,两边是对方棋子
if (board[row][1] == piece &&
board[row][0] == opponent &&
board[row][2] == opponent) {
return true;
}
}
// 检查纵向被夹吃的情况
for (int col = 0; col < 3; col++) {
// 中间是当前棋子,两边是对方棋子
if (board[1][col] == piece &&
board[0][col] == opponent &&
board[2][col] == opponent) {
return true;
}
}
return false;
}
}
import sys
t = int(sys.stdin.readline())
for _ in range(t):
a, kou, yukari = [sys.stdin.readline().strip() for _ in range(3)], 0, 0
for i in range(3):
if (a[i] == "*o*") + (a[0][i] + a[1][i] + a[2][i] == "*o*"):
kou = 1
elif (a[i] == "o*o") + (a[0][i] + a[1][i] + a[2][i] == "o*o"):
yukari = 1
if kou and not yukari:
print("kou")
elif yukari and not kou:
print("yukari")
else:
print("draw") #include <iostream>
using namespace std;
int main() {
int t;cin>>t;
while(t--){
char a[3][3];
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
cin>>a[i][j];
}
}
int o=0,x=0;
if(a[0][1]=='o'&&a[0][0]=='*'&&a[0][2]=='*'||a[2][1]=='o'&&a[2][0]=='*'&&a[2][2]=='*') o++;
if(a[0][1]=='*'&&a[0][0]=='o'&&a[0][2]=='o'||a[2][1]=='*'&&a[2][0]=='o'&&a[2][2]=='o') x++;
if(a[1][0]=='o'&&a[0][0]=='*'&&a[2][0]=='*'||a[1][2]=='o'&&a[0][2]=='*'&&a[2][2]=='*') o++;
if(a[1][0]=='*'&&a[0][0]=='o'&&a[2][0]=='o'||a[1][2]=='*'&&a[0][2]=='o'&&a[2][2]=='o') x++;
if(a[1][1]=='o'){
if(a[1][0]=='*'&&a[1][2]=='*') o++;
if(a[0][1]=='*'&&a[2][1]=='*') o++;
}
if(a[1][1]=='*'){
if(a[1][0]=='o'&&a[1][2]=='o') x++;
if(a[0][1]=='o'&&a[2][1]=='o') x++;
}
if(o>0&&x==0) cout<<"kou"<<endl;
else if(o==0&&x>0) cout<<"yukari"<<endl;
else cout<<"draw"<<endl;
}
} 不是哥们这就过了?
public class Program {
public static void Main() {
string line=System.Console.ReadLine();
int n = int.Parse(line);
for(int i=0;i<n;++i){
slov();
}
}
static void slov(){
bool kou =false;
bool yukari =false;
string [] bord =new string [3];
bord[0]=System.Console.ReadLine();
bord[1]=System.Console.ReadLine();
bord[2]=System.Console.ReadLine();
for(int i=0;i<3;++i){
if(bord[i] == "o*o"){
yukari =true;
}
if(bord[i]=="*o*"){
kou=true;
}
}
for(int j=0;j<3;++j){
string col ="";
col+=bord[0][j];
col+=bord[1][j];
col+=bord[2][j];
if(col == "o*o"){
yukari =true;
}
if(col=="*o*"){
kou=true;
}
}
if(yukari&&!kou){
System.Console.WriteLine("yukari");
}
else if(kou&&!yukari){
System.Console.WriteLine("kou");
}
else{
System.Console.WriteLine("draw");
}
}
} #include <iostream>
using namespace std;
#include <vector>
#include <string>
int main(){
int t;
cin >> t;
for(int i = 0; i < t; ++i){
vector<string> v;
int count1 = 0, count2 = 0;
for(int j = 0; j < 3; ++j){
string s;
cin >> s;
v.push_back(s);
if(s == "*o*") count1++;
if(s == "o*o") count2++;
}
for(int a = 0; a < 3; ++a){
string ss;
for(int b = 0; b < 3; ++b){
ss += v[b][a];
}
if(ss == "*o*") count1++;
if(ss == "o*o") count2++;
}
if(count1 != 0 && count2 == 0) cout << "kou" << endl;
else if(count1 == 0 && count2 != 0) cout << "yukari" << endl;
else cout << "draw" << endl;
}
return 0;
} def solve():
# 读取棋盘
board = []
for _ in range(3):
board.extend(list(input().strip()))
# 存储索引
black_indices = [i for i, char in enumerate(board) if char == '*']
white_indices = [i for i, char in enumerate(board) if char == 'o']
def is_captured(target_idx, opponent_indices):
r, c = divmod(target_idx, 3)
# 检查横向夹吃 (同行)
# 必须是 (r, 0) 和 (r, 2) 夹住 (r, 1)
if c == 1:
if (target_idx - 1) in opponent_indices and (target_idx + 1) in opponent_indices:
return True
# 检查纵向夹吃 (同列)
# 必须是 (0, c) 和 (2, c) 夹住 (1, c)
if r == 1:
if (target_idx - 3) in opponent_indices and (target_idx + 3) in opponent_indices:
return True
return False
red_eaten = any(is_captured(i, white_indices) for i in black_indices)
purple_eaten = any(is_captured(i, black_indices) for i in white_indices)
# 胜负判定
if red_eaten and not purple_eaten:
print("yukari") # 小红被吃,小紫胜
elif purple_eaten and not red_eaten:
print("kou") # 小紫被吃,小红胜
else:
print("draw")
# 处理多组数据
t = int(input())
for _ in range(t):
solve() #include <iostream>
using namespace std;
#include<vector>
int main() {
int t;
cin >> t;
while (t--) {
vector<vector<char>>v(3, vector<char>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
char qizi;
cin >> qizi;
v[i][j]=qizi;
}
}
bool baizi_win = 0, heizi_win = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (v[i][j] == 'o') {
if (i == 1) {
if (v[i - 1][j] == '*' && v[i + 1][j] == '*') {
heizi_win = 1;
}
}
if (j == 1) {
if (v[i][j - 1] == '*' && v[i][j + 1] == '*') {
heizi_win = 1;
}
}
}
if (v[i][j] == '*') {
if (i == 1) {
if (v[i - 1][j] == 'o' && v[i + 1][j] == 'o') {
baizi_win = 1;
}
}
if (j == 1) {
if (v[i][j - 1] == 'o' && v[i][j + 1] == 'o') {
baizi_win = 1;
}
}
}
}
}
if(heizi_win==1&&baizi_win==0){
cout<<"kou"<<endl;
}
else if(heizi_win==0&&baizi_win==1){
cout<<"yukari"<<endl;
}
else{
cout<<"draw"<<endl;
}
}
}
// 64 位输出请用 printf("%lld") def main():
t = int(input())
for _ in range(t):
chessboard = [input().strip() for _ in range(3)]
yukari_flag = False
kou_flag = False
for i in range(3):
if 'o*o' == chessboard[i]:
yukari_flag = True
if '*o*' == chessboard[i]:
kou_flag = True
for i in range(3):
col_tmp = ''
for j in range(3):
col_tmp += chessboard[j][i]
if 'o*o' == col_tmp:
yukari_flag = True
if '*o*' == col_tmp:
kou_flag = True
if yukari_flag == kou_flag:
print('draw')
elif yukari_flag:
print('yukari')
else:
print('kou')
if __name__ == '__main__':
main() #include <iostream>
#include <vector>
using namespace std;
int is_win(char mp[3][3]) {
int h = 0, z = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (mp[i][j] == 'o') {
if (j + 2 < 3 && mp[i][j + 2] == 'o' && mp[i][j + 1] == '*') {
h = 1;
continue;
}
if (j - 2 > 0 && mp[i][j - 2] == 'o' && mp[i][j - 1] == '*') {
h = 1;
continue;
}
if (i - 2 > 0 && mp[i - 2][j] == 'o' && mp[i - 1][j] == '*') {
h = 1;
continue;
}
if (i + 2 < 3 && mp[i + 2][j] == 'o' && mp[i + 1][j] == '*') {
h = 1;
continue;
}
}
if (mp[i][j] == '*') {
if (j + 2 < 3 && mp[i][j + 2] == '*' && mp[i][j + 1] == 'o') {
z = 1;
continue;
}
if (j - 2 > 0 && mp[i][j - 2] == '*' && mp[i][j - 1] == 'o') {
z = 1;
continue;
}
if (i - 2 > 0 && mp[i - 2][j] == '*' && mp[i - 1][j] == 'o') {
z = 1;
continue;
}
if (i + 2 < 3 && mp[i + 2][j] == '*' && mp[i + 1][j] == 'o') {
z = 1;
continue;
}
}
}
}
if (h == 0 && z == 0) return 0;
if (h == 1 && z == 0) return 2;
if (h == 0 && z == 1) return 1;
return 0;
}
int main() {
int n, i = 0;
char mp[3][3];
cin >> n;
int c = n * 3;
while (c--) {
string s;
cin >> s;
for (int j = 0; j < 3; j++) {
mp[i][j] = s[j];
}
i++;
if (i == 3) {
i = 0;
int r = is_win(mp);
if (r == 1) {
cout << "kou" << endl;
} else if (r == 2) {
cout << "yukari" << endl;
} else {
cout << "draw" << endl;
}
}
}
}