• 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;
    }
  • 相关阅读:
    软件工程第1次阅读作业
    软件工程第0次作业
    OO第四次博客
    OO第三次总结
    OO第二次总结
    OO第一次总结
    提问回顾与个人总结
    结对项目:最长单词链
    第一次阅读作业
    第四次博客
  • 原文地址:https://www.cnblogs.com/-citywall123/p/11353915.html
Copyright © 2020-2023  润新知