Tic-Tac-Toe (模拟)

8人阅读 评论(0) 收藏 举报
分类:

Tic-Tac-Toe

Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.

The game is played on the following field.

Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field.

You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip.

A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules.


Input

First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell.

The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right.

It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.

Output

Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.

Examples
Input
... ... ...
... ... ...
... ... ...

... ... ...
... ... ...
... x.. ...

... ... ...
... ... ...
... ... ...
6 4
Output
... ... ... 
... ... ... 
... ... ... 

... ... ... 
... ... ... 
... x.. ... 

!!! ... ... 
!!! ... ... 
!!! ... ... 

Input
xoo x.. x..
ooo ... ...
ooo ... ...

x.. x.. x..
... ... ...
... ... ...

x.. x.. x..
... ... ...
... ... ...
7 4
Output
xoo x!! x!! 
ooo !!! !!! 
ooo !!! !!! 

x!! x!! x!! 
!!! !!! !!! 
!!! !!! !!! 

x!! x!! x!! 
!!! !!! !!! 
!!! !!! !!! 

Input
o.. ... ...
... ... ...
... ... ...

... xxx ...
... xox ...
... ooo ...

... ... ...
... ... ...
... ... ...
5 5
Output
o!! !!! !!! 
!!! !!! !!! 
!!! !!! !!! 

!!! xxx !!! 
!!! xox !!! 
!!! ooo !!! 

!!! !!! !!! 
!!! !!! !!! 
!!! !!! !!! 

Note

In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.

In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell.

In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable.

题目要求很简单,就是题目又臭又长,就是给你一个大的九宫格,每个九宫格又是一个小的九宫格,给定一个坐标,通过这个坐标在小的九宫格的位置,找到相应的大的九宫格的位置例如

... ... ...
... ... ...
... ... ...

... ... ...
... ... ...
... x.. ...

... ... ...
... ... ...
... ... ...
6 4
x是小的九宫格的位置,所以对应的大九宫格就是红色部分

让我们如果这个部分有点就变成!,然后输出全部,如果这部分全被ox占了,就把整个图中的.变成!然后输出全部。

取模找位置就行了

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char G[12][12];
int x,y;
int main(){
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            scanf("%c",&G[i][j]);
            if(j % 3 == 0) getchar();
        }
        if(i % 3 == 0 && i != 9) getchar();
    }
    scanf("%d%d",&x,&y);
    x = (x - 1) % 3 + 1;
    y = (y - 1) % 3 + 1;//得到大九宫格的位置
    int flag = 0;
    int sx = 3 * (x - 1) + 1;
    int sy = 3 * (y - 1) + 1;
    for(int i = sx; i < sx + 3; i++){
        for(int j = sy; j < sy + 3; j++){
            if(G[i][j] == '.'){
                G[i][j] = '!';
                flag = 1;
            }
        }
    }
    if(flag){
        for(int i = 1; i <= 9; i++){
            for(int j = 1; j <= 9; j++){
                printf("%c",G[i][j]);
                if(j % 3 == 0 && j != 9)
                    printf(" ");
            }
            printf("\n");
            if(i % 3 == 0 && i != 9)
                printf("\n");
        }
    }
    else{
        for(int i = 1; i <= 9; i++){
            for(int j = 1; j <= 9; j++){
                if(G[i][j] == '.') printf("!");
                else printf("%c",G[i][j]);
                if(j % 3 == 0 && j != 9)
                    printf(" ");
            }
            printf("\n");
            if(i % 3 == 0 && i != 9)
                printf("\n");
        }
    }
    return 0;
}


查看评论

ATM取款机模拟实战项目

我们从现实生活中的ATM取款机的广泛使用,来确定我们编写ATM取款机程序的功能。首先,用户的登陆、用户的取款、用户的查询、用户的转帐、用户密码的修改等功能。根据实际功能的需求完成我们的程序。 “ATM取款机项目”主要描述“ATM取款机”的工作原理,与实际生活相结合,编写一个模拟实战项目。
  • 2015年05月12日 14:29

907B - Tic-Tac-Toe

B. Tic-Tac-Toe time limit per test 2 seconds memory limit per test 256 megabytes input standar...
  • memory_qianxiao
  • memory_qianxiao
  • 2017-12-25 19:10:26
  • 194

CF 3C Tic-tac-toe

此题只要考虑全面就可以额 愁死了 #include #include #include using namespace std; char data[5][5]; int _win[2][...
  • H1deonbush
  • H1deonbush
  • 2015-07-09 16:07:21
  • 314

LWC 74: 794. Valid Tic-Tac-Toe State

LWC 74: 794. Valid Tic-Tac-Toe State 传送门:794. Valid Tic-Tac-Toe State Problem: A Tic-Tac-Toe b...
  • u014688145
  • u014688145
  • 2018-03-05 21:58:54
  • 131

【Light OJ】No More Tic-tac-toe (博弈 SG函数)

题目链接: http://acm.bnu.edu.cn/v3/problem_show.php?pid=13319 一道典型的求解SG函数的题目,校内组队赛中遇到此题。开题时有比较清晰...
  • zhan723284893
  • zhan723284893
  • 2015-06-06 18:45:42
  • 582

Cdoeforces 754 B - Ilya and tic-tac-toe game

Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs....
  • Tsaryu
  • Tsaryu
  • 2017-01-08 13:40:44
  • 850

codeforces 3C Tic-tac-toe

C. Tic-tac-toe time limit per test 1 second memory limit per test 64 megabytes inpu...
  • ahoLic
  • ahoLic
  • 2014-04-03 13:00:37
  • 2474

CF_3C_Tic-tac-toe

C. Tic-tac-toe time limit per test 1 second memory limit per test 64 megabytes inpu...
  • baidu_29410909
  • baidu_29410909
  • 2016-03-23 22:12:50
  • 255

C. Tic-tac-toe【模拟】

C. Tic-tac-toe time limit per test 1 second memory limit per test 64 megabytes inpu...
  • liuke19950717
  • liuke19950717
  • 2016-06-10 21:31:35
  • 596

tic-tac-toe游戏java程序下载

  • 2011年05月10日 12:48
  • 8KB
  • 下载
    个人资料
    持之以恒
    等级:
    访问量: 3万+
    积分: 4144
    排名: 9095
    文章存档
    最新评论