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

int card[6][6],selected[26],cardx[6][6],I[26],J[26];
//cardx另一塊板子紀錄哪個位子
int col_checker(int x)
{
     int line=0;
     for(int i=1;i<=5;i++)
     {
          line+=cardx[i][x];
     }
     if(line==5)return 1;
     else if(x<5)col_checker(x+1);
     else return 0;
}
int row_checker(int x)
{
     int line=0;
     //printf("x=%d\n",x);
     for(int i=1;i<=5;i++)
     {
          line+=cardx[x][i];
          //printf("line=%d\n",line);
     }
     if(line==5)
     {
          //printf("x=%d",x);
          return 1;
     }
     else if(x<5)row_checker(x+1);
     else return 0;
}
int cnt_checker(void)
{
     int line=0;
     for(int i=1;i<=5;i++)
     {
          line+=cardx[i][i];
     }
     if(line==5)return 1;
     line=0;
     for(int i=1;i<=5;i++)
     {
          line+=cardx[i][6-i];
     }
     if(line==5)return 1;
     else return 0;
}

int main(void)
{
    int T,N,reward_num=0;
    int ans[102]={0};

    for(int i=1; i<=5; i++)
    {
        for(int j=1; j<=5; j++)
        {
            scanf("%d",&card[i][j]);
            I[card[i][j]]=i;
            J[card[i][j]]=j;//標位置
        }
    }
    //printf("%d=%d,%d\n",card[1][1],I[1],J[1]);
    scanf("%d",&T);
    for(int k=1;k<=T;k++)
    {
        scanf("%d",&N);
        for(int i=1; i<=N; i++)
        {
            scanf("%d",&selected[i]);
            cardx[I[selected[i]]][J[selected[i]]]=1;//選到設1
            if(i>=5&&reward_num==0)
            {
                 if(col_checker(1)||row_checker(1)||cnt_checker())reward_num=i;
            }
        }

        if(reward_num)ans[k]=reward_num;
        reward_num=0;
        for(int i=1; i<=5; i++)//return to zero
        {
            for(int j=1; j<=5; j++)
            {
                cardx[i][j]=0;
            }
        }
    }
    for(int k=1;k<=T;k++)
    {
         printf("Case #%d: ",k);
         if(ans[k])printf("%d\n",ans[k]);
         else printf("Not yet \\(^o^)/\n");
    }
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.