-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Solution.java
30 lines (27 loc) · 857 Bytes
/
Solution.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
// github.com/RodneyShag
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
for (int i = 0; i < T; i++) {
String str = scan.next();
printEvensOdds(str);
}
scan.close();
}
/* For efficient appending, use a StringBuffer instead of a String */
public static void printEvensOdds(String str) {
StringBuffer evens = new StringBuffer();
StringBuffer odds = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if (i % 2 == 0) {
evens.append(ch);
} else {
odds.append(ch);
}
}
System.out.println(evens + " " + odds);
}
}