forked from purushottamnawale/geeksforgeeks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargest number possible.cpp
More file actions
51 lines (45 loc) · 863 Bytes
/
Largest number possible.cpp
File metadata and controls
51 lines (45 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//{ Driver Code Starts
// Initial Template for C++
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
// User function Template for C++
class Solution
{
public:
string findLargest(int n, int S)
{
string res = "";
if ((S <= 0 && n > 1) || (S > 9 * n))
return "-1";
for (int i = 0; i < n; i++)
{
if (S > 9)
{
res += '9';
S -= 9;
}
else if (S <= 9)
{
res += to_string(S);
S = 0;
}
}
return res;
}
};
//{ Driver Code Starts.
int main()
{
int t;
cin >> t;
while (t--)
{
int N, S;
cin >> N >> S;
Solution ob;
cout << ob.findLargest(N, S) << "\n";
}
return 0;
}
// } Driver Code Ends