
- 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 of typing game after delay timing
Suppose we have five numbers s, v1, v2, t1 and t2. Amal and Bimal are playing a typing game, they are playing their game online. In this game they will type a string whose length is s. Amal types one character in v1 milliseconds and Bimal types one character in v2 milliseconds. Amal's network delay is t1 milliseconds, and Bimal's network delay is t2 milliseconds.
If the connection delay is t milliseconds, the competition passes for a participant as follows −
Exactly after t milliseconds after the game start the participant receives the text to be entered.
Right after that he starts to type it.
Exactly t milliseconds after he ends typing all the text, the site receives information about it.
Who completes faster, will be the winner. If the time for both participants are same, then it is a draw. We have to find the winner.
So, if the input is like s = 5; v1 = 1; v2 = 2; t1 = 1; t2 = 2, then the output will be Amal, because information on the success of Amal comes in 7 milliseconds, of Bimal in 14 milliseconds. So, Amal wins.
Steps
To solve this, we will follow these steps −
p := (s * v1) + (2 * t1) q := (s * v2) + (2 * t2) if p is same as q, then: return "Draw" otherwise when p < q, then: return "Amal" Otherwise return "Bimal"
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; string solve(int s, int v1, int v2, int t1, int t2) { int p = (s * v1) + (2 * t1); int q = (s * v2) + (2 * t2); if (p == q) return "Draw"; else if (p < q) return "Amal"; else return "Bimal"; } int main() { int s = 5; int v1 = 1; int v2 = 2; int t1 = 1; int t2 = 2; cout << solve(s, v1, v2, t1, t2) << endl; }
Input
5, 1, 2, 1, 2
Output
Amal
- Related Articles
- C++ program to find winner of card game
- 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
- C++ Program to find winner name of stick crossing game
- Program to find winner of stone game in Python
- 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
- Python program to find score and name of winner of minion game
- Program to find winner of a set element removal game in Python
- C++ program to find maximum possible amount of allowance after playing the game
- Predict the winner in Coin Game in C++
