-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2017-Q-2.cpp
58 lines (45 loc) · 906 Bytes
/
2017-Q-2.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
/*
* Written by Nitin Kumar Maharana
* nitin.maharana@gmail.com
*/
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void)
{
int t;
string input, result;
string::iterator start, end;
unsigned long long int j, k, len;
cin >> t;
for(int i = 1; i <= t; i++)
{
cin >> input;
len = input.length();
for(j = len-1ull; j > 0ull; j--) {
if(input[j-1ull] > input[j]) {
for(k = j; k < len && input[k] != '9'; k++)
input[k] = '9';
input[j-1ull] = input[j-1ull]-1;
}
}
start = input.begin();
while((*start) == '0')
start++;
end = input.end();
result.assign(start, end);
cout << "Case #" << i << ": " << result << endl;
}
return 0;
}