Ac- 简单题

来源:互联网 发布:在线兼职美工 编辑:程序博客网 时间:2024/06/03 12:13

Description

小卡和欢总喜欢玩一个小游戏,游戏界面是4*4格子的棋盘,每个格子可以放一个棋子。

最开始的时候棋盘上只有一个棋子,叫'T'。

接下来欢总和小卡轮流放棋子,小卡的棋子是'X',欢总是'O'。

如果有一行或一列或一条对角线上全部是某个选手的棋子(4个)或者3个他的棋子和'T',这个选手就赢了,游戏结束。 如果所有格子都满了,没有人赢,以平局结束。

给你一个棋局,你要告诉我们:

"X won" 游戏结束,小卡赢了;"O won" 游戏结束,欢总赢了;"Draw" 游戏结束,平局结束;"Game has not completed" 游戏还没结束。

如果还有空格子,那么游戏还没结束,你应该输出"Game has not completed"。

Input Format

第一行给出数据组数T,1<=T<=500。

接下来T组,每组4行,每行4个字符,是'X','O','T'或'.'。其中'.'表示空格子。

每组结束之后有一个空行。

Output Format

输出T行,每行输出一个结果。

Sample Input

6XXXT....OO......XOXTXXOOOXOXXXOOXOX.OX..........OOXXOXXXOX.TO..OXXXO..O..O..T...OXXXXO....O....O

Sample Output

X wonDrawGame has not completedO wonO wonO won
#include <iostream>using namespace std;bool is_there_dot(char qipan[5][5]){    for(int i=0;i<4;i++)    {        for(int j=0;j<4;j++)        {            if(qipan[i][j]=='.')return true;        }    }    return false;}bool is_there_win(char judge,char qipan[5][5]){    int count=0,T_num,sum;    bool flag=false;    if(judge=='O'){T_num=1;}    else{T_num=-1;}    sum=T_num*4;    for(int i=0;i<4;i++)    {        count=0;        for(int j=0;j<4;j++)        {            if(qipan[i][j]==judge||qipan[i][j]=='T')            {                count+=T_num;            }        }        if(count==sum){return true;}    }    for(int j=0;j<4;j++)    {        count=0;        for(int i=0;i<4;i++)        {            if(qipan[i][j]==judge||qipan[i][j]=='T')            {                count+=T_num;            }        }        if(count==sum){return true;}    }    count=0;    for(int i=0;i<4;i++)    {        if(qipan[i][i]==judge||qipan[i][i]=='T')        {            count+=T_num;        }    }    if(count==sum){return true;}    count=0;    for(int i=0;i<4;i++)    {        if(qipan[i][3-i]==judge||qipan[i][3-i]=='T')        {            count+=T_num;        }    }    if(count==sum){return true;}    return false;}int main(){    bool dot;    int n,x_num,o_num;    char qipan[500][5][5];    cin>>n;    for(int i=0;i<n;i++)    {        for(int j=0;j<4;j++)        {            cin>>qipan[i][j];        }    }    for(int i=0;i<n;i++)    {        dot=is_there_dot(qipan[i]);        x_num=is_there_win('X',qipan[i]);        o_num=is_there_win('O',qipan[i]);        if(x_num==1)cout<<"X won";        else if(o_num==1)cout<<"O won";        else        {            if(dot==true)cout<<"Game has not completed";            else{cout<<"Draw";}        }        cout<<endl;    }}


0 0
原创粉丝点击