
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ Program to find winner name of stick crossing game
Suppose we have two numbers n and k. Amal and Bimal are playing a game. The rules are simple. Amal draws n sticks in a row. After that the players take turns crossing out exactly k sticks from left or right in each turn. Amal starts the game. If there are less than k sticks on the paper before some turn, the game ends. Amal wins if he makes strictly more moves than Bimal. We have to find who will be the winner.
So, if the input is like n = 10; k = 4, then the output will be Bimal. Because Amal crosses out 4 sticks, then Bimal crosses out 4 sticks, and after that there are only 2 sticks left. Amal can't make a move. The players make equal number of moves, so Amal doesn't win.
Steps
To solve this, we will follow these steps −
if floor of (n / k) is even, then: return "Amal" return "Bimal"
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; string solve(int n, int k) { if ((n / k) % 2 != 0) { return "Amal"; } return "Bimal"; } int main() { int n = 10; int k = 4; cout << solve(n, k) << endl; }
Input
10, 4
Output
Bimal
- Related Articles
- Python program to find score and name of winner of minion game
- C++ program to find winner of card game
- Program to find winner of stone game in Python
- C++ program to find winner of cell coloring game
- C++ program to find winner of ball removal game
- C++ Program to find winner of unique bidding game
- Program to find winner of array removal game in Python
- Program to find winner of number reducing game in Python
- Program to find the winner of an array game using Python
- Program to find winner of a rower reducing game in Python
- Program to find winner of a rower breaking game in Python
- C++ program to find winner of typing game after delay timing
- Program to find winner of a set element removal game in Python
- Predict the winner in Coin Game in C++
- Program to find length of longest possible stick in Python?
