Untitled
raw download clone
C
views 17
,
size 2018 b
#include <stdio.h>

boarda[5][5];
boardb[5][5];
void find(int a);
int suc(void);

int main(void)
{
    for (int i = 0;i < 5;i++)
    {
        for (int j = 0;j < 5;j++)
        {
            scanf("%d", &boarda[i][j]);
        }
    }
    int T, N, test[26] = {0};
    scanf("%d", &T);
    for (int h = 1;h <= T;h++)
    {
        for (int i = 0;i < 5;i++)
        {
            for (int j = 0;j < 5;j++)
            {
                boardb[i][j] = 0;
            }
        }

        scanf("%d", &N);
        int x = 0;
        for (int i = 1;i <= N;i++)
        {
            scanf("%d", &test[i]);
            find(test[i]);
            if (suc() == 1) x = i;
        }
        if (x == 0)
        {
            printf("Case #%d: Not yet \(^o^)/\n", h);
        }
        else
        {
            printf("Case #%d: %d\n", h, x);
        }
    }

    return 0;
}


void find(int a)
{
    for (int i = 0;i < 5;i++)
    {
        for (int j = 0;j < 5;j++)
        {
            if (a == boarda[i][j])
            {
                boardb[i][j] = 1;
            }
        }
    }


}

int suc(void)
{
    //橫排
    for (int i = 0;i < 5;i++)
    {
        int flag = 0;
        for (int j = 0;j < 5;j++)
        {
            if (boardb[i][j] != 1) flag = 1;
        }
        if (flag == 0) return 1;
    }
    //直排
    for (int i = 0;i < 5;i++)
    {
        int flag = 0;
        for (int j = 0;j < 5;j++)
        {
            if (boardb[j][i] != 1) flag = 1;
        }
        if (flag == 0) return 1;
    }
    //左斜
    int flag1 = 0;
    for (int i = 0, j = 0;i < 5, j < 5;i++, j++)
    {

        if (boardb[i][j] != 1) flag1 = 1;
    }
    if (flag1 == 0)
    {
        return 1;
    }
    //右斜
    int flag2 = 0;
    for (int i = 4,j = 0;i > 0, j < 5;i--, j++)
    {
        if (boardb[i][j] != 1) flag2 = 1;
    }
    if (flag2 == 0)
    {
        return 1;
    }
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.