Game

G. Game

3000ms
3000ms
131072KB
64-bit integer IO format: %lld      Java class name: Main
Font Size:

[PDF Link]

Tic-tac-toe is the third most popular activity to kill a lazy afternoon in Ardenia (right after solving puzzles and insulting your neighbors). Arthum and Breece are not fans of this game, but their mother told them to play, so they sit at a5 x 5 board. Both have a large pile of marbles: marbles of Arthum have anA written on them and that of Breece have a B. However, as they are both two years old, they have no concept of rounds. Instead, they just toss their marbles as quick as possible, so after a while each board field has either marbleA or marble B.

At that point, they would like to determine the winner, but counting is not their strong point, either. (They are two years old, remember?) Recall that the goal of tic-tac-toe is to have three own marbles in a row, i.e., lying at three consecutive fields horizontally, vertically or diagonally. If both Arthum and Breece have their three marbles in a row, or neither of them has it, we call it a draw.

Input

The input contains several test cases. The first line of the input contains a positive integer Z$ \le$105, denoting the number of test cases. Then Z test cases follow, each conforming to the format described below.

The input instance describes marbles placed on the board in a single game. The instance consists of 5 rows and each of them consists of 5 letters:A or B.

Output

For each test case, your program has to write an output conforming to the format described below.

You should output one line describing the outcome of the game, i.e., one of the three possible strings:A wins, B wins, or draw.

Sample Input

2 
AABBA 
BAAAB 
AAABA 
ABAAB 
BAAAB 
AAAAA 
AAAAA 
BAAAA 
ABAAA 
AABAA

Sample Output

A wins 
draw

 

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char a[10][10];
int  f1,f2;
void check(char a[10][10])
{
  int i,j;
  for(i=1;i<=5;i++)
    for(j=1;j<=5;j++){
      if(a[i][j]==a[i][j+1]&&a[i][j+1]==a[i][j+2]){         // 每行
         if(a[i][j]=='A')    f1=1;
         else  if(a[i][j]=='B')                f2=1;                                      
      }                 
      if(a[i][j]==a[i+1][j]&&a[i+1][j]==a[i+2][j]){         // 每列  
         if(a[i][j]=='A')    f1=1;
         else  if(a[i][j]=='B')                f2=1;                                      
      }
      if(a[i][j]==a[i+1][j+1]&&a[i+1][j+1]==a[i+2][j+2]){    // 左上右下对角线
         if(a[i][j]=='A')    f1=1;
         else if(a[i][j]=='B')                 f2=1;                                      
      }       
   if(a[i][j]==a[i-1][j+1]&&a[i-1][j+1]==a[i-2][j+2]){    // 左下右上对角线
         if(a[i][j]=='A')    f1=1;  
         else   if(a[i][j]=='B')           f2=1;                                                   
      }                                         
    }   
}
int main(){
    int t,i,j,f=0;
    scanf("%d",&t);
    getchar();
    while(t--){
      memset(a,0,sizeof(a));
      for(i=1;i<=5;i++){
       for(j=1;j<=5;j++)
           scanf("%c",&a[i][j]);
       getchar();
      }
      f1=0;  f2=0;
      check(a);
      if(f1==1&&f2==0)  printf("A wins\n");
      else if(f2==1&f1==0)  printf("B wins\n");
      else         printf("draw\n");              
   }
   system("pause");
   return 0;   
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值