- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ code to find how many upgrade to make HP greater than current

Suppose we have a number n. In a game, every character has four different health points (HP). The categories are as follows −

Category A : If HP is in the form (4n + 1)

Category B : If HP is in the form (4n + 3)

Category C : If HP is in the form (4n + 2)

Category D : If HP is in the form 4n

These 4 categories ordered from highest to lowest as A > B > C > D. So, category A is the highest and category D is the lowest. While playing the game, players can increase the HP of the character. Now, Amal wants you to increase his HP by at most 2 (that is, either by 0, 1 or 2). We have to find how much should he increase his HP so that it has the highest possible category?

So, if the input is like n = 98, then the output will be 1 B, because 98 is in category C as (4*24 + 2), by increasing it by 1, it will be upgraded to category B, but if we increase it to 2, it will be 100 (4*25) which is category D. So at max category B is possible.

## Steps

To solve this, we will follow these steps −

if n mod 4 is same as 2, then: return "1 B" Otherwise return |(n mod 4) - 1| and 'A'

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; void solve(int n){ if (n % 4 == 2) cout << "1 B"; else cout << abs(n % 4 - 1) << " A"; } int main(){ int n = 98; solve(n); }

## Input

98

## Output

1 B

- Related Questions & Answers
- C++ program to check how many students have greater score than first one
- C++ program to find in how many bases we can represent the number not greater than M
- How to find the smallest number greater than x in Python?
- Counting How Many Numbers Are Smaller Than the Current Number in JavaScript
- C++ code to find out which number can be greater
- C++ code to find greater number whose factor is k
- Python - Find words greater than given length
- C++ program to find minimum how many operations needed to make number 0
- C++ code to count numbers after division elements greater than half of array size
- C++ code to find maximum fruit count to make compote
- C++ code to find max ornaments to make decoration good
- Program to find how many updates required to make string half monotonous in Python
- Find Smallest Letter Greater Than Target in Python
- Find smallest element greater than K in Python
- Find Smallest Letter Greater Than Target in JavaScript