Tic-Tac-Toe
Description
Kim likes to play Tic-Tac-Toe.
Given a current state, and now Kim is going to take his next move. Please tell Kim if he can win the game in next 2 moves if both player are clever enough.
Here “next 2 moves” means Kim’s 2 move. (Kim move,opponent move, Kim move, stop).

Game rules:
Tic-tac-toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row wins the game.
Input
First line contains an integer T (1 ≤ T ≤ 10), represents there are T test cases.
For each test case: Each test case contains three lines, each line three string(“o” or “x” or “.”)(All lower case letters.)
x means here is a x
o means here is a o
. means here is a blank place.
Next line a string (“o” or “x”) means Kim is (“o” or “x”) and he is going to take his next move.
Output
For each test case:
If Kim can win in 2 steps, output “Kim win!”
Otherwise output “Cannot win!”
Sample Input
Sample Output







#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
int i,j,k,l,m,n,t,q;
char a[][],b;
scanf("%d",&t);
for(l=;l<t;l++)
{
k=;q=;
for(i=;i<;i++)
for(j=;j<;j++)
scanf(" %c",&a[i][j]);
scanf(" %c",&b);
for(i=;i<;i++)
for(j=;j<;j++)
if(a[i][j]==b)
q++;
if(q<)
printf("Cannot win!\n");
else
{
if(a[][]==b||a[][]=='.')
printf("Kim win!\n");
else
printf("Cannot win!\n");
}
}
return ;
}
在这里有一个网站可以和人机玩一下这个游戏。
Tic-Tac-Toe的更多相关文章
- Principle of Computing (Python)学习笔记(7) DFS Search + Tic Tac Toe use MiniMax Stratedy
1. Trees Tree is a recursive structure. 1.1 math nodes https://class.coursera.org/principlescomputin ...
- POJ 2361 Tic Tac Toe
题目:给定一个3*3的矩阵,是一个井字过三关游戏.开始为X先走,问你这个是不是一个合法的游戏.也就是,现在这种情况,能不能出现.如果有人赢了,那应该立即停止.那么可以知道X的步数和O的步数应该满足x= ...
- 【leetcode】1275. Find Winner on a Tic Tac Toe Game
题目如下: Tic-tac-toe is played by two players A and B on a 3 x 3 grid. Here are the rules of Tic-Tac-To ...
- 2019 GDUT Rating Contest III : Problem C. Team Tic Tac Toe
题面: C. Team Tic Tac Toe Input file: standard input Output file: standard output Time limit: 1 second M ...
- [CareerCup] 17.2 Tic Tac Toe 井字棋游戏
17.2 Design an algorithm to figure out if someone has won a game oftic-tac-toe. 这道题让我们判断玩家是否能赢井字棋游戏, ...
- Epic - Tic Tac Toe
N*N matrix is given with input red or black.You can move horizontally, vertically or diagonally. If ...
- python 井字棋(Tic Tac Toe)
说明 用python实现了井字棋,整个框架是本人自己构思的,自认为比较满意.另外,90%+的代码也是本人逐字逐句敲的. minimax算法还没完全理解,所以参考了这里的代码,并作了修改. 特点 可以选 ...
- ACM-Team Tic Tac Toe
我的代码: #include <bits/stdc++.h> using namespace std; int main() { char a[3][3]; int i,j=0; for( ...
- LeetCode 5275. 找出井字棋的获胜者 Find Winner on a Tic Tac Toe Game
地址 https://www.acwing.com/solution/LeetCode/content/6670/ 题目描述A 和 B 在一个 3 x 3 的网格上玩井字棋. 井字棋游戏的规则如下: ...
- 【Python五篇慢慢弹】数据结构看python
数据结构看python 作者:白宁超 2016年10月9日14:04:47 摘要:继<快速上手学python>一文之后,笔者又将python官方文档认真学习下.官方给出的pythondoc ...
随机推荐
- TeamViewer13个人版使用中提示为商用版导致无法使用
前言:由于使用teamviewer个人免费版较频繁,被软件识别到不能再继续免费使用,无奈没有多余的资金进行购买正版软件, 通过鼓捣得到如下继续免费使用方案,整理下来以备不时之需,也可以被有同此困惑的朋 ...
- 继续深入更新shell脚本容易出错的地方
一.在shell中用到如果需要输入某些值,需要用到read -p命令 这是我写的猜数字游戏,一开始在输出的时候,屏幕上总会打印输出 "INT" 经过反复的练习才发现 双引号后面应 ...
- JSP工作流程
情况1:第一次请求一个页面 情况2:该页虽然是再次请求,但已经过修改 情况3:该页面是再次请求且未被修改
- mysql索引建立原则
看了网上一些网上关于创建索引的原则,在这里做一下总结: 1.尽量创建在使用频率较高的字段上,比如主键,外键,where总用到的字段,join是相关联的字段 2.如果表过大,一定要创建索引. 3.索引应 ...
- 面试乐融集团Python开发工程师有感
这是笔者第一次面试,,乐融集团位于朝阳区朝阳公园的乐融大厦.是下午两点的笔面试,笔者是一点半到的,然后在里面等了会,开始笔试 笔试题并不是太难,就是考的比较宽,因为笔者是校招,所以笔试题出来了数据结构 ...
- pip快速git项目安装
pip install git+https://github.com/xx/xx.git
- u-boot.2012.10makefile分析,良心博友汇总
声明:以下内容大部分来自网站博客文章,仅作学习之用1.uboot系列之-----顶层Makefile分析(一)1.u-boot.bin生成过程分析 2.make/makefile中的加号+,减号-和a ...
- 最新Altium_Designer_Beta_18.7.is AD18安装教程及破解说明
下解Altium_Designer带破解的压缩包. 下载链接:https://pan.baidu.com/s/1TlPHtSthJKxLcXWcCR-q-g 密码:bt0g 解压缩Altium_Des ...
- 关于C链表的实现
学习了数据结构后,自己学习写了一个链表的程序.初步功能是实现了.但是不知道会不会有一些隐含的问题.所以希望大佬指导指导 /******************/ /*一个小的链表程序*/ /***** ...
- STM32 时钟配置的坑
今天在调试公司的一款产品的时候发现8M的晶振用完了,于是找了一个16M的替代 坑爹的就在这里,明明已经把时钟按照时钟树配置好了,但是串口等外设一直无法正常工作 折腾了一下午,终于发现这位老兄的文章ht ...