
- 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 maximum possible amount of allowance after playing the game
Suppose we have three numbers A, B and C. Consider a game: There are three "integer panels", each with a digit form 1 to 9 (both inclusive) printed on it, and one "operator panel" with a '+' sign printed on it. The player should make a formula of the form X+Y, by arranging the four panels from left to right. Then, the amount of the allowance will be equal to the resulting value of the formula.
We have to find the maximum possible amount of the allowance.
So, if the input is like A = 1; B = 5; C = 2, then the output will be 53, because the panels are arranged like 52+1, and this is the maximum possible amount.
Steps
To solve this, we will follow these steps −
Define an array V with A, B and C sort the array V ans := (V[2] * 10) + V[1] + V[0] return ans
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; int solve(int A, int B, int C){ vector<int> V = { A, B, C }; sort(V.begin(), V.end()); int ans = (V[2] * 10) + V[1] + V[0]; return ans; } int main(){ int A = 1; int B = 5; int C = 2; cout << solve(A, B, C) << endl; }
Input
1, 5, 2
Output
53
- Related Articles
- Program to find minimum possible maximum value after k operations in python
- C++ Program to find maximum score of bit removal game
- C++ program to find winner of typing game after delay timing
- Program to find maximum score of brick removal game in Python
- Program to find maximum score in stone game in Python
- C++ program to find maximum possible value of XORed sum
- Program to find maximum possible population of all the cities in python
- Program to find number of possible moves to start the game to win by the starter in Python
- Program to find out the maximum points collectable in a game in Python
- Program to find maximum possible value of smallest group in Python
- C++ Program to find array after removal from maximum
- C++ program to find maximum possible value for which XORed sum is maximum
- C++ program to find out the maximum possible tally from given integers
- Program to find maximum score we can get in jump game in Python
- Program to find all possible IP address after restoration in C++

Advertisements