2017 青岛网络赛 Chenchen, Tangtang and ZengZeng

Chenchen, Tangtang and ZengZeng are starting a game of tic-tac-toe, played on a 3 × 3 board.

Initially, all squares on the board are empty and they takes turns writing the first letter of their name into any of the empty squares (because Chenchen, Tangtang and ZengZeng are elites, their names have different first letters, ’C’, ’T’ and ’Z’ respectively). The game ends when anyone of them places 3 of his letters consecutively in a row, column or diagonally. That people is declared the winner.

Write a program that, given the state of the board, determines if the game is over and who won if it is.

Input

The input contains several test cases up to 1000. Each case contains three lines describing the board. Each line contains 3 characters. The characters will be uppercase letters of {′C′,′ T′,′ Z′} or ’.’ (if the square is empty). The data will be such that there is at most one winner

Output

For each case, if the game is over, output the first letter of the winner’s name. If not, output “ongoing” even if the board if full.

样例输入复制
4
CTZ
TCZ
CTZ
ZCT
CZC
TTZ
.C.
C.T
Z..
CTZ
.C.
CTZ
样例输出复制
Z
Z
ongoing
ongoing

题意:一个三行三列的棋盘,规则和五子棋一样,Z,C,T代表三个人,.代表空位置,输出赢得那个人得名字

#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<string>
#include<string.h>
#include<vector>
#include<utility>
#include<map>
#include<queue>
#include<set>
#define mx 0x3f3f3f3f
#define ll long long
using namespace std;
string s[1005];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        for(int i=0;i<3;i++)
            cin>>s[i];
        int flag=0;
        for(int i=0;i<3;i++)
        {
            if(s[i][1]==s[i][0]&&s[i][1]==s[i][2]&&s[i][1]!='.')//
            {
                cout<<s[i][1]<<endl;
                flag=1;
                break;
            }
            else if(s[0][i]==s[1][i]&&s[1][i]==s[2][i]&&s[1][i]!='.')//
            {
                cout<<s[1][i]<<endl;
                flag=1;
                break;
            }
            else if(s[0][0]==s[1][1]&&s[1][1]==s[2][2]&&s[1][1]!='.')//主对角线
            {
                cout<<s[1][1]<<endl;
                flag=1;
                break;
            }
            else if(s[1][1]==s[0][2]&&s[1][1]==s[2][0]&&s[1][1]!='.')//副对角线
            {
                cout<<s[1][1]<<endl;
                flag=1;
                break;
            }
        }
        if(flag==0)
            cout<<"ongoing"<<endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/-citywall123/p/11353915.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值