2017 Qingdao network game 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.

Sample input

4 
CTZ 
TCZ 
CTZ 
ZCT 
CZC 
TTZ 
.C. 
CT 
Z .. 
CTZ 
.C. 
CTZ

Sample Output

The Z- 
the Z- 
Ongoing 
Ongoing 

meaning of the questions: a chessboard three rows and three columns, rules, and the 331, Z, C, T on behalf of three people, representing an empty position, that person was the name of the output win.

#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;
}

 

Guess you like

Origin www.cnblogs.com/-citywall123/p/11353915.html