zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    centos 8.5设置nginx开机自动启动
    python利用Faker模块造测试数据(转载)
    结构化分析建模
    关于使用com.anjiplus依赖实现的验证码功能在linux服务器上失效的问题
    vue 子组件提交接口,父组件刷新数据
    vue 全局钩子:路由守卫
    Scala函数式编程基础
    Flink
    Scala面向对象编程
    Scala运算符
  • 原文地址:https://www.cnblogs.com/-citywall123/p/11353915.html
Copyright © 2011-2022 走看看