-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcode_1.java
More file actions
64 lines (63 loc) · 1.63 KB
/
code_1.java
File metadata and controls
64 lines (63 loc) · 1.63 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
61
62
63
64
import java.util.Scanner;
public class code_1 {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
int n = sc.nextInt();
int k = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
StringBuilder str = new StringBuilder(s);
StringBuilder str_first = new StringBuilder();
int start = 0;
int end = k-1;
boolean check = true;
while(start<=end){
if(check){
str_first.append(str.charAt(start));
start++;
check = false;
}
else{
str_first.append(str.charAt(end));
end--;
check = true;
}
}
str_first.reverse();
str_first.append(str.substring(k, n));
System.out.println(str_first.toString());
// char ar[] = s.toCharArray();
// char ar_one[] = new char [k];
// if(k%2==0){
// int mid = k/2;
// for(int i=0,j=0;i<k;i++){
// if(i%2==0){
// ar_one[i] = ar[mid+j];
// }
// else{
// ar_one[i] = ar[mid-j-1];
// j++;
// }
// }
// }
// else{
// int mid = k/2;
// for(int i=0,j=0;i<k;i++){
// if(i%2==0){
// ar_one[i] = ar[mid-j];
// j++;
// }
// else{
// ar_one[i] = ar[mid+j];
// }
// }
// }
// for(int i=0;i<k;i++){
// System.out.print(ar_one[i]);
// }
// for(int i=k;i<n;i++){
// System.out.print(ar[i]);
// }
// System.out.println();
}
}