Codeforces 3C. Tic-tac-toe
来源:互联网 发布:淘宝客吸引人的广告词 编辑:程序博客网 时间:2024/06/08 18:19
代码:
#include <stdio.h>#include <math.h>#include <algorithm>#include <vector>using namespace std;const int MAXN = 100005;int chessBoard[4][4];int Test(int x1, int x2, int x3){ if(x2 == x1 && x2 == x3) return x2; return 0;}int main(){#ifdef _LOCAL freopen("F://input.txt", "r", stdin);#endif int countX = 0, countO = 0; for(int i = 1; i <= 3; ++i) { for(int j = 1; j <= 3; ++j) { char ch; scanf("%c", &ch); if(ch == 'X') { countX++; chessBoard[i][j] = 1; } else if(ch == '0') { countO++; chessBoard[i][j] = 2; } } getchar(); } if(countO > countX || countX - countO > 1) { printf("illegal\n"); return 0; } vector<int> ans; for(int i = 1; i <= 3; ++i) { ans.push_back(Test(chessBoard[i][1], chessBoard[i][2], chessBoard[i][3])); ans.push_back(Test(chessBoard[1][i], chessBoard[2][i], chessBoard[3][i])); } ans.push_back(Test(chessBoard[1][1], chessBoard[2][2], chessBoard[3][3])); ans.push_back(Test(chessBoard[1][3], chessBoard[2][2], chessBoard[3][1])); sort(ans.begin(), ans.end()); int last = ans.size() - 1; if(ans[last - 1] == 1 && ans[last] == 2 || ans[last] == 2 && countX > countO || ans[last] == 1 && countX == countO) { printf("illegal\n"); return 0; } if(ans[last] == 1) printf("the first player won\n"); else if(ans[last] == 2) printf("the second player won\n"); else if(countX + countO == 9) printf("draw\n"); else if(countX == countO) printf("first\n"); else printf("second\n"); return 0;}
0 0
- codeforces 3C. Tic-tac-toe
- codeforces 3C Tic-tac-toe
- Codeforces 3C. Tic-tac-toe
- Codeforces 3 C. Tic-tac-toe
- CodeForces 3C-Tic-tac-toe
- Codeforces 3C Tic-tac-toe
- [Codeforces]C. Tic-tac-toe
- Codeforces Beta Round #3C. Tic-tac-toe
- Codeforces Beta Round #3 C. Tic-tac-toe
- codeforces 3C Tic-tac-toe (想法题)
- CodeForces 3C Tic-tac-toe 井字棋盘游戏
- CodeForces 3C---Tic-tac-toe--思维题
- codeforces - 3C - Tic-tac-toe(模拟)
- Codeforces Beta Round #3-C. Tic-tac-toe
- CodeForces 3C Tic-tac-toe(模拟)
- C - Tic-tac-toe
- CF 3C Tic-tac-toe
- CF 3C Tic-tac-toe
- 算法学习 - 不申请第三个数交换两个整数的值
- route 路由
- 适合IT人自学的几个视频网站
- jsp 用urlrewrite 实现URL 重写
- UVA10294项链和手镯(等价类计数问题)
- Codeforces 3C. Tic-tac-toe
- struts2实现文件下载所出现的乱码,解决方法
- 第十五周项目三:OJ(一)
- nyoj410 how many ones?
- 文件编码UTF-8控制台输出乱码的问题
- 基于配置文件的方式来配置 AOP
- 回顾过去的2014
- c++矩阵
- Java 程序 ——感想