
- 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++ code to find minimum different digits to represent n
Suppose we have a number n. We want to split it into some non-zero digits whose sum is n. We want to find a solution with minimum possible number of different digits.
So, if the input is like n = 13, then the output will be [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Steps
To solve this, we will follow these steps −
for initialize i := 0, when i < n, update (increase i by 1), do: print 1
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; void solve(int n){ for (int i = 0; i < n; i++) printf("1, "); } int main(){ int n = 13; solve(n); }
Input
13
Output
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- Related Articles
- C++ code to find minimum number starting from n in a game
- Program to find minimum digits sum of deleted digits in Python
- C++ code to find minimum arithmetic mean deviation
- C++ program to count minimum number of binary digit numbers needed to represent n
- C++ code to find minimum difference between concerts durations
- C++ code to find minimum stones after all operations
- C++ code to find minimum jump to reach home by frog
- C++ code to find minimum time needed to do all tasks
- C++ code to find minimum moves with weapons to kill enemy
- C++ code to find total number of digits in special numbers
- Different ways to represent N as the sum of K non-zero integers
- C++ code to find minimum k to get more votes from students
- C++ code to find minimum operations to make numbers c and d
- C++ code to find minimum correct string from given binary string
- C++ code to find screen size with n pixels

Advertisements