-
Notifications
You must be signed in to change notification settings - Fork 0
/
RotateAndCut.java
executable file
·45 lines (40 loc) · 1.29 KB
/
RotateAndCut.java
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created by Ziver on 2016-10-11.
*/
public class RotateAndCut {
public static void main(String[] args) throws IOException {
RotateAndCut rotateAndCut = new RotateAndCut();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int count = Integer.parseInt(in.readLine());
for (int i = 0; i <count; i++) {
char c;
int cuts = 0;
while ((c = (char) in.read()) != ' ')
cuts = cuts * 10 + c-'0';
System.out.println(
rotateAndCut.calc(
cuts,
in.readLine()));
}
in.close();
}
public String calc(int cuts, String originalMsg) {
int start = 0;
int end = originalMsg.length();
int currentLength = end;
boolean cutInFront = true;
while (cuts > 0 && currentLength > 3){
currentLength = end - start;
if (cutInFront)
start += currentLength / 4;
else
end -= currentLength / 4;
--cuts;
cutInFront = !cutInFront;
}
return originalMsg.substring(start, end);
}
}