-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcodejam2017QRProblemB.cpp
More file actions
60 lines (60 loc) · 1.13 KB
/
codejam2017QRProblemB.cpp
File metadata and controls
60 lines (60 loc) · 1.13 KB
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<algorithm>
#include<iostream>
using namespace std;
int main()
{ int t;
cin>>t;
for(int i=1; i<=t; i++)
{ string N, out;
cin>>N;
out=N;
bool x=0; //not done.
sort(out.begin(), out.end());
for(int j=out.length()-1; j>=0 && x==0; j--)
{ for(char k=out[j]; k<='9'; k++)
{ char temp=out[j];
out[j]=k;
if(out>N)
{ out[j]=temp;
x=1;
break;
}
}
}
while(out[0]<'9')
{ string t=out;
out[0]++;
for(int j=1; j<out.length(); j++)
out[j]=out[j-1];
bool x=0;
if(out<N)
{ for(int j=out.length()-1; j>=0 && x==0; j--)
{ for(char k=out[j]; k<='9'; k++)
{ char temp=out[j];
out[j]=k;
if(out>N)
{ out[j]=temp;
x=1;
break;
}
}
}
}
else
{ out=t;
break;
}
}
//cout<<out;
cout<<"Case #"<<i<<": ";
int j;
for(j=0; j<out.length(); j++)
{ if(out[j]!='0')
break;
}
for(; j<out.length(); j++)
cout<<out[j];
cout<<'\n';
}
return 0;
}