Codeforces Beta Round #3
来源:互联网 发布:矩阵力学的主要创立者 编辑:程序博客网 时间:2024/06/05 18:28
Description
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3 × 3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.
You are given a 3 × 3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:
- illegal — if the given board layout can't appear during a valid game;
- the first player won — if in the given board layout the first player has just won;
- the second player won — if in the given board layout the second player has just won;
- draw — if the given board layout has just let to a draw.
Input
The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).
Output
Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.
Sample Input
X0X.0..X.
second
暴力求解:
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>using namespace std;char a[5][5];int numx,numo;bool row(char aim){ for(int i=0;i<3;i++){ int j; for(j=0;j<3;j++) if(a[i][j]!=aim) break; if(j==3) return 1; } return 0;}bool col(char aim){ for(int j=0;j<3;j++){ int i; for(i=0;i<3;i++) if(a[i][j]!=aim) break; if(i==3) return 1; } return 0;}bool xie(char aim){ if((a[1][1]==aim&&a[0][0]==a[1][1]&&a[1][1]==a[2][2])||(a[1][1]==aim&&a[0][2]==a[1][1]&&a[2][0]==a[1][1])) return 1; else return 0;}void judge(){ if((numx-numo)==0||(numx-numo)==1){ int ans1=0; ans1=col('X'); ans1+=row('X'); ans1+=xie('X'); int ans2=0; ans2=col('0'); ans2+=row('0'); ans2+=xie('0'); if(ans1&&!ans2){ if(numx-numo==1) cout<<"the first player won"<<endl; else cout<<"illegal"<<endl; return ; }else if(!ans1&&ans2){ if(numx==numo) cout<<"the second player won"<<endl; else cout<<"illegal"<<endl; return ; }else if(ans1&&ans2){ cout<<"illegal"<<endl; }else if(numx+numo==9){ cout<<"draw"<<endl; }else{ if(abs(numx-numo)==1) cout<<"second"<<endl; else if(numx==numo) cout<<"first"<<endl; } } else cout<<"illegal"<<endl;}int main(){ numx=0;numo=0; for(int i=0;i<3;i++) { gets(a[i]); for(int j=0;j<3;j++) if(a[i][j]=='X') numx++; else if(a[i][j]=='0') numo++; } judge();}
- Codeforces Beta Round #3
- Codeforces Beta Round #3
- Codeforces Beta Round #3
- Codeforces Beta Round #3
- Codeforces Beta Round #3
- Codeforces Beta Round #3
- Codeforces Beta Round #3 练习
- Codeforces Beta Round #3 B
- Codeforces Beta Round #3 B. Lorry
- Codeforces Beta Round #3 B. Lorry
- Codeforces Beta Round #2
- Codeforces Beta Round #24
- Codeforces Beta Round #64
- Codeforces Beta Round #23
- Codeforces Beta Round #88
- Codeforces Beta Round #88
- Codeforces Beta Round #91
- Codeforces Beta Round #93
- 运动目标检测--三种方法比较
- 机器视觉开源代码集合-2
- 解决spark缺少winutils.exe的问题
- 非3D Touch的设备上模拟Peek Preview效果
- stm32中GPIO端口的输出配置例子
- Codeforces Beta Round #3
- JAVA反射机制
- C++第7次作业
- 对字节读写操作示例,来自微软
- jQuery创建节点和插入节
- 排序算法(5)-希尔排序
- 第十周、十一周项目
- 整理的es中的mapping方面的内容
- 郑轻OJ 1099: 角谷猜想(多实例测试)