CodeForce 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.

 

#include <iostream>
#include <cstdio>

using namespace std;

char MAP[12][12];
int main(void)
{
	for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			scanf(" %c",&MAP[i][j]);
		}
	}
	
	int x,y;//小宫格的位置 
	scanf("%d %d",&x,&y);
	
	int bx,by;//对应大宫格的位置
	bx = (x - 1) % 3 + 1;
	by = (y - 1) % 3 + 1;
	//cout << bx << " " << by << endl;
	
	int sx,sy;//找到大宫格对应的开始的位置(4,4)对应(1,1) 
	sx = (bx - 1) * 3 + 1;
	sy = (by - 1) * 3 + 1;
	//cout << sx << " " << sy << endl;
	
	int flag = 0;
	for(int i=sx; i<sx+3; i++){
		for(int j=sy; j<sy+3; j++){
			if(MAP[i][j] == '.'){
				flag = 1;
				MAP[i][j] = '!';
			}
		}
	}
	
	if(flag == 1){//找到了 
		for(int i=1; i<=9; i++){
			for(int j=1; j<=9; j++){
				printf("%c", MAP[i][j]);
				if(j % 3 == 0){
					printf(" ");
				}
			}
			
			cout << endl;
			if(i % 3 == 0){
				cout << endl;
			}
		}
	}else{
		for(int i=1; i<=9; i++){
			for(int j=1; j<=9; j++){
				if(MAP[i][j] == '.'){
					MAP[i][j] = '!';
				}
				cout << MAP[i][j];
				if( j % 3 == 0){
					printf(" ");
				}	
			}
			cout << endl;
			if(i % 3 == 0){
				cout << endl;
			}
		}
	}

	return 0;
}

/*
题意:

一共有九个小宫格,组成一个大宫格,可以在每个空格里下x或者是o(空的是.)
下了的就不能再下了。
在小九宫格里下的位置,把对应大九宫格的位置可以下的位置替换为!
如果无法替换,即替换的位置已经落子或者找不到对应替换的地方,
就把大九宫格全部的.替换为! 

*/

例如样例1,在小九宫格左下角下面下的,就把大九宫格的左下角. 替换为!。如果无法替换(替换的地方落子了)或者没有对应替换的地方,就把大九宫格全部的.替换为!,例如样例2和3.

版权声明:本文为xiaorui98原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xiaorui98/article/details/100068111

智能推荐

2018.8.27

2018.8.27...

HTML 表单元素的基本样式

HTML 表单元素的基本样式 原创 ixygj197875 发布于2018-02-22 17:48:53 阅读数 2296 收藏 更新于2018-05-20 15:35:58 分类专栏: 揭秘 CSS 揭秘 CSS 收起 表单元素主要包括 label、input、textarea、select、datalist、******、progress、meter、output等,以及对表单元素进行分组的 ...

php输出语句

php输出语句 常见的输出语句 echo(): 可以一次输出多个值,多个值之间用逗号分隔。echo是语言结构(language construct),而并不是真正的函数,因此不能作为表达式的一部分使用。 print(): 函数print()打印一个值(它的参数),如果字符串成功显示则返回true,否则返回false。 print_r(): 可以把字符串和数字简单地打印出来,而数组则以括起来的键和值...

工厂模式

简介 常见的实例化对象模式。 用工厂方法替代new操作的一种模式。 当我们使用new操作实例化对象时,调用构造函数完成初始化。若初始化仅是进行赋值等简单的操作,写入构造函数即可。但如果初始化时需要执行一长串复杂的代码,将多个工作装入一个方法,是不妥的。 创建实例与使用实例分离。将创建实例所需的大量初始化工作从基类的构造函数中分离出去。 简单工厂模式、工厂方法模式针对的是一个产品等级结构;而抽象工厂...

B1105 Spiral Matrix (画图)

B1105 Spiral Matrix (25分) //第一次只拿了21分 矩阵的长和宽,求最大因子,从sqrt(num)开始枚举. 每次循环一次,s++,t--,d--,r++ 测试点四运行超时,是因为输入一个数字的时候,需要直接输出这个数字。//1分 测试点二运行超时,最后一个数字不必再while循环一次,直接输出即可。//3分 最后一个测试点卡了好久/(ㄒoㄒ)/~~ 螺旋矩阵...

猜你喜欢

Java基础=>String,StringBuffer与StringBuilder的区别

字符串常量池 什么是字符串常量池? JVM为了减少字符串对象的重复创建,其维护了一块特殊的内存,这段内存被称为字符串常量池(存储在方法区中)。 具体实现 当代码中出现字符串时,JVM首先会对其进行检查。 如果字符串常量池中存在相同内容的字符串对象,如果有,则不再创建,直接返回这个对象的地址返回。 如果字符串常量池中不存在相同内容的字符串对象,则创建一个新的字符串对象并放入常量池,并返回新创建的字符...

java调用其他java项目的Https接口

项目中是这样的: 用户拿出二维码展示,让机器识别二维码, 机器调用开门的后台系统接口, 然后开门的后台系统接口需要调用管理系统的接口, 管理系统需要判断能不能开门.这两个系统是互相独立的.当时使用http调用是没有问题的.当时后来要求必须用https.废话不说,直接代码: 我的项目中调用的是 HttpsUtils.Get(utlStr) 这个接口 开门系统接口如下图:   管理系统的接口...

Hadoop1.2.1全分布式模式配置

一 集群规划 主机名            IP                               安装的软件 &nbs...

Go语言gin框架的安装

尝试安装了一下gin,把遇到的一些小问题来记录一下 安装步骤 首先来看看官方文档,链接点这里 可以看到安装步骤很简单,就一句话 在命令行中输入这句话运行等待就好。 问题来了,因为墙的问题,go get会很慢,所以命令行里面半天什么反应也没有,不要急,慢慢等着就会看到gin-gonic/gin这个目录出现 这个时候命令行还是没有结束,表示还在下一些东西。有的时候可能心急的人就停了(比如我),然后写个...

uni-app表单组件二

input(输入框) 属性名 类型 说明 平台差异 value String 输入框的初始内容 type String input 的类型 password Boolean(默认false) 是否是密码类型 placeholder String 输入框为空时占位符 placeholder-style String 指定 placeholder 的样式 placeholder-class Strin...