题解 | #井字棋#

井字棋

https://www.nowcoder.com/practice/0375c1d206ef48a3894f72aa07b2fdde

#include <stdio.h>

int main() {
    char arr[3][3];
    for (int i = 0; i < 3; i++) 
    {
        for (int j = 0; j < 3; j++) 
        {
            arr[i][j] = getchar();
            getchar();
        }
    }
    int count = 0;
    for (int i = 0; i < 3; i++)
    {
        int j = 1;
        if ((arr[i][j] == arr[i][j - 1]) && (arr[i][j] == arr[i][j + 1]))
        {
            if (arr[i][j] == 'K')
            {
                count = 1;
                break;
            }
            else if (arr[i][j] == 'B')
            {
                count = -1;
                break;
            }

        }
        

    }

    for (int j = 0; j < 3; j++)
    {
        int i = 1;
        if ((arr[i][j] == arr[i - 1][j]) && (arr[i][j] == arr[i + 1][j]))
        {
            if (arr[i][j] == 'K')
            {
                count = 1;
                break;
            }
            else if (arr[i][j] == 'B')
            {
                count = -1;
                break;
            }

        }
        

    }

    int i = 1;
    int j = 1;
    if ((arr[i][j] == arr[i - 1][j - 1]) && (arr[i][j] == arr[i + 1][j + 1]))
    {
        if (arr[i][j] == 'K')
        {
            count = 1;
        }
        else if (arr[i][j] == 'B')
        {
            count = -1;
        }

        
    }

    if ((arr[i][j] == arr[2][0]) && (arr[i][j] == arr[0][2]))
    {
        if (arr[i][j] == 'K')
        {
            count = 1;
        }
        else if (arr[i][j] == 'B')
        {
            count = -1;
        }

        
    }
    
    if (count == 1)
        printf("KiKi wins!\n");
    else if (count == 0)
        printf("No winner!\n");
    else
        printf("BoBo wins!\n");


    return 0;
}

全部评论

相关推荐

11-24 00:11
已编辑
广东工业大学 算法工程师
避雷深圳&nbsp;&nbsp;yidao,试用期&nbsp;6&nbsp;个月。好嘛,试用期还没结束,就直接告诉你尽快找下一家吧,我谢谢您嘞
牛客75408465号:笑死,直属领导和 hr 口径都没统一,各自说了一些离谱的被裁理由,你们能不能认真一点呀,哈哈哈哈哈😅😅😅
点赞 评论 收藏
分享
10-24 13:36
门头沟学院 Java
Zzzzoooo:更新:今天下午有hr联系我去不去客户端,拒了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务