-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathQuestion_26_notfound.cpp
127 lines (55 loc) · 1.26 KB
/
Question_26_notfound.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Question 26
___________
*/
#include<bits/stdc++.h>
using namespace std ;
int sum_of_digits(string &n)
{
int len = n.length();
int sum = 0;
for(int i = 0 ; i < len ; i++)
{
sum = sum + (n[i]-48) ;
}
return sum ;
}
string convert(string &n)
{
string new_str;
int len = n.length();
int req_digit = 9 - sum_of_digits(n)%9;
if(req_digit == 9)
{
n.insert(1 , "0");
}
else
{
int flag = 0 ;
char s = req_digit+48;
for(int i =0 ; i < len ; i++)
{
if(s < n[i] && flag ==0 )
{
flag = 1;
n.insert(i,string(1,s));
break;
}
}
if(flag ==0 )
n.insert(len,string(1,s));
}
return n;
}
int main()
{
int t ;
cin >> t;
for(int i =1 ; i <= t ; i++)
{
string n ;
cin >> n ;
n = convert(n);
cout <<"Case #"<<i <<": " << n << "\n";
}
}