Play Games 2

CONCEPTS USED:

Game theory

DIFFICULTY LEVEL:

Easy.

PROBLEM STATEMENT$($SIMPLIFIED$)$:

Arnab wants to play games with his friend. He made a pile of chocolates and now he will take the first move and the players can remove chocolates of value 2,3,4 turn by turn. And if any person fails to take the chocolates, he will lose.

See original problem statement here

For Example :

Input
5
12 
20 
31 
33 
71 

Output
Friend
Arnab
Friend
Arnab
Arnab

OBSERVATION:

This is a simple observation question on online programming practice where you could clearly see that, if the remainder is 0 or 1,the friend loses.

Else Arnab.

SOLUTION:

#include <bits/stdc++.h>
using namespace std;

void solve(int n) 
{
   string an="";
    int ans = n%6;
    if(ans==0||ans==1)
       an="Friend";
    else
      an="Arnab";   

    an+='\n';

    cout<<an;
}

int main()
{  

  int t;
  cin>>t;
  while(t--)
  {
    int n;
    cin>>n;
    solve(n);
  }

return 0;
}

Previous post Play Games 4
Next post Quiz Test

Leave a Reply

Your email address will not be published. Required fields are marked *