Codeforces 3C
来源:互联网 发布:乌斯玛草 知乎 编辑:程序博客网 时间:2024/06/03 19:05
题意
给你一个井字棋的棋谱,判断井字棋的状态
first, 第一个人走
second 第二个人走
illegal 不合法
the first player won 第一个人赢
the second player won 第二个人赢
draw 平局
思路
暴力枚举每种赢的状态
答案中没有这种样例 (思考一下)
X0X00X0XX
代码
/* **********************************************Auther: Çë½ÐÎÒacmÔüÔüCreated Time: 2015-7-29 15:37:22File Name : 3c.cpp*********************************************** */#include <iostream>#include <fstream>#include <cstring>#include <climits>#include <deque>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <utility>#include <sstream>#include <complex>#include <string>#include <vector>#include <cstdlib>#include <cstdio>#include <ctime>#include <bitset>#include <functional>#include <algorithm>using namespace std;#define lson L,m,rt<<1#define rson m+1,R,rt<<1|1#define ll long long#define N 11111char mp[4][4];int flag1 ;int flag2 ;void judge1(){ if(mp[0][0]=='X'&&mp[0][1]=='X'&&mp[0][2]=='X') flag1 = 1; if(mp[1][0]=='X'&&mp[1][1]=='X'&&mp[1][2]=='X') flag1 = 1; if(mp[2][0]=='X'&&mp[2][1]=='X'&&mp[2][2]=='X') flag1 = 1; if(mp[0][0]=='X'&&mp[1][0]=='X'&&mp[2][0]=='X') flag1 = 1; if(mp[0][1]=='X'&&mp[1][1]=='X'&&mp[2][1]=='X') flag1 = 1; if(mp[0][2]=='X'&&mp[1][2]=='X'&&mp[2][2]=='X') flag1 = 1; if(mp[0][0]=='X'&&mp[1][1]=='X'&&mp[2][2]=='X') flag1 = 1; if(mp[0][2]=='X'&&mp[1][1]=='X'&&mp[2][0]=='X') flag1 = 1;}void judge2(){ if(mp[0][0]=='0'&&mp[0][1]=='0'&&mp[0][2]=='0') flag2 = 1; if(mp[1][0]=='0'&&mp[1][1]=='0'&&mp[1][2]=='0') flag2 = 1; if(mp[2][0]=='0'&&mp[2][1]=='0'&&mp[2][2]=='0') flag2 = 1; if(mp[0][0]=='0'&&mp[1][0]=='0'&&mp[2][0]=='0') flag2 = 1; if(mp[0][1]=='0'&&mp[1][1]=='0'&&mp[2][1]=='0') flag2 = 1; if(mp[0][2]=='0'&&mp[1][2]=='0'&&mp[2][2]=='0') flag2 = 1; if(mp[0][0]=='0'&&mp[1][1]=='0'&&mp[2][2]=='0') flag2 = 1; if(mp[0][2]=='0'&&mp[1][1]=='0'&&mp[2][0]=='0') flag2 = 1;}int main(){ for(int i=0;i<3;i++){ scanf("%s",mp[i]); } int cnt1=0,cnt2=0; flag1 = 0; flag2 = 0; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ if(mp[i][j]=='X') cnt1++; if(mp[i][j]=='0') cnt2++; } } // printf("%d %d %d\n",cnt1,cnt2,abs(cnt1-cnt2)); judge1(); judge2(); if(cnt1-cnt2>1||cnt2>cnt1){ puts("illegal"); return 0; } if(cnt1+cnt2!=9&&abs(cnt1-cnt2)<=1){ if(flag1&&flag2) puts("illegal"); else if(flag1&&cnt1>cnt2) puts("the first player won"); else if(flag2&&cnt2==cnt1) puts("the second player won"); else if(flag2&&cnt1>cnt2||(flag1&&cnt1==cnt2)) puts("illegal"); else{ if(cnt1>cnt2) puts("second"); else puts("first"); } } if(cnt1+cnt2==9){ if(flag1&&flag2) puts("illegal"); if(!flag1&&!flag2) puts("draw"); if(flag1) puts("the first player won"); if(flag2) puts("illegal"); }}
0 0
- CodeForces 3C
- Codeforces 3C
- Codeforces Educational Codeforces Round 3 C. Load Balancing(贪心)
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- codeforces 3C. Tic-tac-toe
- codeforces 3C Tic-tac-toe
- Codeforces 3C. Tic-tac-toe
- Codeforces 3 C. Tic-tac-toe
- 【暑假测试3】B CodeForces 560C
- CodeForces 3C-Tic-tac-toe
- Educational Codeforces Round 3 C. Load Balancing
- Codeforces 3C Tic-tac-toe
- codeforces 863C 1-2-3
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Map.keySet 和 Map.entrySet 的效率问题
- Linux 下安装phpredis
- 高阶函数,集合
- eclipse点击后出现exit code=13
- 马拦过河卒
- Codeforces 3C
- 小白学开发(iOS)OC_new方法原理(2015-07-29)
- android Socket 编程
- Opencv常见用法和常见错误(一)
- java:IO流学习小结
- python生成式生成器
- 数据结构一:企业级顺序存储底层库封装
- SharePoint 2013 调查问卷的用法
- C语言获取系统时间的方法