-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLongBeautifulInteger.java
More file actions
47 lines (47 loc) · 999 Bytes
/
LongBeautifulInteger.java
File metadata and controls
47 lines (47 loc) · 999 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
import java.io.*;
import java.util.*;
public class LongBeautifulInteger {
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] temp = br.readLine().split(" ");
int num_digits = Integer.parseInt(temp[0]);
int k = Integer.parseInt(temp[1]);
char[] temp2 = br.readLine().toCharArray();
int[] x = new int[temp2.length];
int[] output = new int[k];
for (int i = 0; i < temp2.length; i++)
{
x[i] = temp2[i] - 48;
}
for (int i = 0; i < k; i ++)
{
output[i] = x[i];
}
boolean increment = false;
for (int i = k; i < x.length ; i++)
{
if (x[i] > output[i%k])
{
increment = true;
break;
}
}
if (increment)
{
for (int i = k-1; i>-1; i--)
{
if (output[i] == 9)
output[i] = 0;
else
{
output[i]++;
break;
}
}
}
System.out.println(x.length);
for (int i = 0; i < x.length; i++)
System.out.print(output[i%k]);
}
}