关闭

Codeforces 3 C. Tic-tac-toe

标签:
523人阅读 评论(0) 收藏 举报
分类:

题目链接:http://codeforces.com/contest/3/problem/C
提示:此题巨坑,一定要注意是illegal的情况

#include <iostream>
#include <cstdio>
using namespace std;
char s[5][5];
int main()
{
    int f1=0,f2=0;
    int sumx=0,sum0=0;
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            cin>>s[i][j];
            if(s[i][j] == 'X')
                sumx++;
            else if(s[i][j] == '0')
                sum0++;
        }
    }
    if(sumx-sum0>1 || sum0>sumx)
        puts("illegal");
    else
    {
        for(int i=0; i<3; i++)
        {
            int sum=0;
            for(int j=0; j<3; j++)
            {
                if(s[i][j] == 'X')
                    sum++;
            }
            if(sum == 3)
            {
                f1=1;
                break;
            }
        }
        for(int i=0; i<3; i++)
        {
            int sum=0;
            for(int j=0; j<3; j++)
            {
                if(s[i][j] == '0')
                    sum++;
            }
            if(sum == 3)
            {
                f2=1;
                break;
            }
        }
        for(int i=0; i<3; i++)
        {
            int sum=0;
            for(int j=0; j<3; j++)
            {
                if(s[j][i] == 'X')
                    sum++;
            }
            if(sum == 3)
            {
                f1=1;
                break;
            }
        }
        for(int i=0; i<3; i++)
        {
            int sum=0;
            for(int j=0; j<3; j++)
            {
                if(s[j][i] == '0')
                    sum++;
            }
            if(sum == 3)
            {
                f2=1;
                break;
            }
        }
        if((s[0][0]=='X'&&s[1][1]=='X'&&s[2][2]=='X')||(s[0][2]=='X'&&s[1][1]=='X'&&s[2][0]=='X'))
            f1=1;
        if((s[0][0]=='0'&&s[1][1]=='0'&&s[2][2]=='0')||(s[0][2]=='0'&&s[1][1]=='0'&&s[2][0]=='0'))
            f2=1;
        if(f1==1&&f2==1 || (f1==1&&f2==0&&(sumx==sum0)) || (f1==0&&f2==1&&(sumx-sum0==1)))
            puts("illegal");
        else if(f1==1&&f2==0&&(sumx-sum0==1))
            puts("the first player won");
        else if(f2==1&&f1==0&&(sumx==sum0))
            puts("the second player won");
        if(f1 + f2 ==0)
        {
            if(sum0 + sumx == 9)
                puts("draw");
            else
            {
                if(sum0==sumx)
                    puts("first");
                else if(sumx>sum0)
                    puts("second");
                else
                    puts("illegal");
            }
        }
    }
    return 0;
}
0
0
查看评论

CodeForces 3C Tic-tac-toe 井字棋盘游戏

CodeForces 3C Tic-tac-toe 井字棋盘游戏
  • wilver
  • wilver
  • 2015-07-09 10:14
  • 595

codeforces 3C Tic-tac-toe

C. Tic-tac-toe time limit per test 1 second memory limit per test 64 megabytes input standard input output standard output ...
  • ahoLic
  • ahoLic
  • 2014-04-03 13:00
  • 2443

Codeforces Beta Round #3 / 3C Tic-tac-toe (超级模拟)

C. Tic-tac-toe http://codeforces.com/problemset/problem/3/C time limit per test 1 second memory limit per test 64 megabytes input ...
  • synapse7
  • synapse7
  • 2013-08-22 00:35
  • 1048

Codeforces 3 C. Tic-tac-toe

题目链接:http://codeforces.com/contest/3/problem/C 提示:此题巨坑,一定要注意是illegal的情况#include <iostream> #include <cstdio> using namespace std; char s[...
  • qingshui23
  • qingshui23
  • 2015-07-08 22:36
  • 523

3c标志国家3C标志图案

  • 2010-01-08 23:54
  • 58KB
  • 下载

【Codeforces 754 B Ilya and tic-tac-toe game】

B. Ilya and tic-tac-toe game time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputIlya...
  • WYK1823376647
  • WYK1823376647
  • 2017-01-07 10:47
  • 782

[Codeforces]C. Tic-tac-toe

time limit per test: 1 second memory limit per test: 64 megabytes input: standard input output: standard outputCertainly, everyone is familiar...
  • ufo123gogo
  • ufo123gogo
  • 2017-04-17 22:10
  • 57

CodeForces 3C Tic-tac-toe(模拟)

题意:XO游戏,现在给你一局游戏,让你判断是否合法,谁获胜,如果还没获胜,则输出下一步由谁走 思路:模拟..细节很多 #include using namespace std; string s[3]; int check(char c) { for(int i=0;i<...
  • qq_21057881
  • qq_21057881
  • 2016-03-28 22:17
  • 337

codeforces 3C. Tic-tac-toe

很古老也很简单的游戏,可是判定规则真的好多好无语啊。。。。。 #include #include #include #include #include #include #include #include #include #include #include...
  • ymrfzr
  • ymrfzr
  • 2013-05-29 22:51
  • 580

C. Tic-tac-toe【模拟】

C. Tic-tac-toe time limit per test 1 second memory limit per test 64 megabytes input standard input output standard output ...
  • liuke19950717
  • liuke19950717
  • 2016-06-10 21:31
  • 382
    个人资料
    • 访问:528834次
    • 积分:11550
    • 等级:
    • 排名:第1588名
    • 原创:639篇
    • 转载:5篇
    • 译文:0篇
    • 评论:93条
    博客专栏