-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC1269.cpp
More file actions
58 lines (48 loc) · 713 Bytes
/
Copy pathC1269.cpp
File metadata and controls
58 lines (48 loc) · 713 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
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, k; cin >> n >> k;
string s; cin >> s;
cout << n << '\n';
string ss = s;
for(int i = 0 ; i < n-k; i++)
{
ss[i+k] = ss[i];
}
if(ss >= s)
{;
cout << ss << '\n';
return 0;
}
for(int i = k-1; i >= 0; i--)
{
if(ss[i] != '9')
{
ss[i]++;
int j = i + k;
while(j < n)
{
ss[j] = ss[i];
j+=k;
}
break;
}else if(ss[i] == '9')
{
ss[i] = '0';
int j = i + k;
while(j < n)
{
ss[j] = ss[i];
j+=k;
}
}
}
cout << ss << '\n';
return 0;
}