-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTidy Numbers.cpp
More file actions
60 lines (52 loc) · 860 Bytes
/
Tidy Numbers.cpp
File metadata and controls
60 lines (52 loc) · 860 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
52
53
54
55
56
57
58
59
60
#include<iostream>
using namespace std;
int main()
{
//freopen("B-large.in","r",stdin);
//freopen("output5.out","w",stdout);
int t;
cin>>t;
for(int i = 1; i<=t; ++i)
{
string a;
string z = "";
cin>>a;
a.push_back('a');
int n = a.length();
cout<<"Case #"<<i<<": ";
int count = 0;
for(int j = 0; j<=n-2; j++)
{
if(a[j]<a[j+1])
{
while(count)
{
z.push_back(a[j]);
count--;
}
z.push_back(a[j]);
count = 0;
}
else if(a[j]==a[j+1])
{
count++;
}
else if(a[j] > a[j+1] && a[j]!='1')
{
z.push_back(a[j] - 1);
for(int x = j+1-count; x<=n-2; x++)
z.push_back('9');
break;
}
else if(a[j] > a[j+1] && a[j]=='1')
{
for(int x = j+1-count; x<=n-2; x++)
z.push_back('9');
break;
}
}
cout<<z;
cout<<"\n";
}
return 0;
}