Can some one help me with this code that I have written for the Game Of Piles Version 1

#include<stdio.h>
int main(){
int T;
scanf(“%d”,&T);
while(T>0){
int N;
scanf(“%d”,&N);
int arr[N];
for(int i=0;i<N;i++){
scanf(“%d”,&arr[i]);
}
int min=arr[0];
for(int i=0;i<N;i++){
if(arr[i]<min){
min=arr[i];
}

    }
   
  
    int count=0;
    
        while(min!=0){
            if(N==1){   
                min=min-1;
                count++;
                if(min==0){
                    break;
                }
            }
            else{
               
                
                for(int i=0;i<N;i++){
                    if(arr[i]<min){
                        min-=1;
                        count++;
                        if(min==0){
                            break;
                        }
                    }

                }
                if(min!=0){                        
                    min=min-1;
                    count++;
                    if(min==0){
                         break;
                    }
                }
                    
            }
        }
    
    if(count%2!=0){
        printf("CHEF\n");
    }
    else{
        printf("CHEFINA\n");
    }
    T--;
}
return 0;

}

@sumer_bassi
Your logic is not right i guess.
since both are playing optimally they will try to remove the stone from the pile having odd number of stores and the first player to remove stone from the pile having even number of stones will loose the game.
Also there is one base condition if in some pile count of stone is 1 then chef will win.

1 Like