
- 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
Minimum number of letters needed to make a total of n in C++.
Problem statement
Given an integer n and let a = 1, b = 2, c= 3, ….., z = 26. The task is to find the minimum number of letters needed to make a total of n
If n = 23 then output is 1 If n = 72 then output is 3(26 + 26 + 20)
Algorithm
1. If n is divisible by 26 then answer is (n/26) 2. If n is not divisible by 26 then answer is (n/26) + 1
Example
#include <iostream> using namespace std; int minRequiredSets(int n){ if (n % 26 == 0) { return (n / 26); } else { return (n / 26) + 1; } } int main(){ int n = 72; cout << "Minimum required sets: " << minRequiredSets(n) << endl; return 0; }
Output
When you compile and execute the above program. It generates the following output −
Minimum required sets: 3
- Related Articles
- C++ program to count minimum number of operations needed to make number n to 1
- Minimum number of Appends needed to make a string palindrome in C++
- Program to check minimum number of characters needed to make string palindrome in Python
- Find minimum number of Log value needed to calculate Log upto N in C++
- C++ program to count minimum number of binary digit numbers needed to represent n
- C++ program to find minimum number of punches are needed to make way to reach target
- C++ program to find minimum how many operations needed to make number 0
- Program to find minimum number of rocketships needed for rescue in Python
- C++ program to find minimum number of operations needed to make all cells at r row c columns black
- Find minimum operations needed to make an Array beautiful in C++
- Minimum number of deletions to make a string palindrome in C++.
- Minimum number of given moves required to make N divisible by 25 using C++.
- Program to find number of coins needed to make the changes in Python
- C++ program to count number of minimum coins needed to get sum k
- Program to count minimum deletions needed to make character frequencies unique in Python

Advertisements