반응형
Day 6: Let's Review | HackerRank
Characters and Strings
www.hackerrank.com
문제
문자열을 입력받아서
홀수 인덱스 문자만, 짝수 인덱스 문자만 따로 나누어서 출력되게 하는 문제
성공 코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for (int i = 0; i < t; i++) {
String str[] = s.next().split("");
String odd = "", even = str[0];
for (int j = 1; j < str.length; j++) {
if (j % 2 == 1)
even += str[j];
else
odd += str[j];
}
System.out.println(even + " " + odd);
}
}
}
|
cs |
반응형