Skip to content

Commit 653f74e

Browse files
committed
added questions
1 parent 54ef667 commit 653f74e

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Harshit knows by his resources that this time the winning lottery number is the smallest number whose sum of the digits is S and the number of digits is D. You have to help Harshit and print the winning lottery number.
3+
Input Format
4+
The Input line contains two space-separated integers: S,D
5+
Output Format
6+
The output contains a single integer denoting the winning lottery number
7+
Constraints
8+
1 <= D <= 1000
9+
1 <= S <= 9*D
10+
Time Limit: 1 second
11+
Sample Input1:
12+
9 2
13+
Sample Output1:
14+
18
15+
Explanation
16+
There are many other possible numbers like 45, 54, 90, etc with the sum of digits as 9 and number of digits as 2. The smallest of them is 18.
17+
*/
18+
#include<bits/stdc++.h>
19+
using namespace std;
20+
int main() {
21+
// Write your code here
22+
int s,d;
23+
cin>>s>>d;
24+
int arr[d];
25+
s=s-1;
26+
for(int i=d-1;i>=0;i--){
27+
if(i==0){
28+
arr[0]=s+1;
29+
break;
30+
}
31+
if(s>=9){
32+
arr[i]=9;
33+
s-=9;
34+
}else{
35+
arr[i]=s;
36+
s=0;
37+
}
38+
}
39+
for(int i=0;i<d;i++){
40+
cout<<arr[i];
41+
}
42+
}

0 commit comments

Comments
 (0)