Game contest4

1569: Game

Time Limit: 8 Sec  Memory Limit: 128 MB
Submit: 57  Solved: 16
[Submit][Status][Web Board]

Description

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 a x 5 board. Both have a large pile of marbles: marbles of Arthum have an A 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 marble A 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 winsB wins, or draw.

Sample Input

2 AABBA BAAAB AAABA ABAAB BAAAB AAAAA AAAAA BAAAA ABAAA AABAA

Sample Output

A wins draw

#include<iostream>
#include
<cmath>
#include
<cstring>
#include
<cstdlib>
#include
<algorithm>
using namespace std;
char num[10][10];
int n,f;
int judge( int i,int j )
{
if( j <= 2 )
{
if( num[i][j] == num[i][j+1] && num[i][j+1] == num[i][j+2] )
return 1;
}
if( i <= 2 )
{
if( num[i][j] == num[i+1][j] && num[i+1][j] == num[i+2][j] )
return 1;
}
if( i >= 2 && j <= 2 )
{
if( num[i][j] == num[i-1][j+1] && num[i][j] == num[i-2][j+2] )
return 1;
}
if( i <= 2 && j <= 2 )
{
if( num[i][j] == num[i+1][j+1] && num[i][j] == num[i+2][j+2] )
return 1;
}
return 0;
}
int main( )
{
scanf(
"%d",&n );
while( n-- )
{
for( int i = 0; i < 5; ++i )
scanf(
"%s",num[i] );
int fa = 0,fb = 0;
for( int i = 0; i < 5; ++i )
for( int j = 0; j < 5; ++j )
{
if( num[i][j] == 'A' && !fa )
fa
= judge( i,j );
if( num[i][j] == 'B' && !fb )
fb
= judge( i,j );
}
if( fa == fb )
puts(
"draw" );
else if( fa )
puts(
"A wins" );
else puts( "B wins" );
}

//system( "pause" );
return 0;
}
/**************************************************************
Problem: 1569
User: HUT_TEAM1
Language: C++
Result: Accepted
Time:100 ms
Memory:1380 kb

posted on 2011-08-04 07:42  more think, more gains  阅读(351)  评论(0编辑  收藏  举报

导航