티스토리 뷰
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
int n = Integer.parseInt(br.readLine());
String word = br.readLine();
if (isMakeOk(word)) {
sb.append(String.format("#%d %s\n", t, "Yes"));
} else {
sb.append(String.format("#%d %s\n", t, "No"));
}
}
System.out.println(sb);
}
static boolean isMakeOk(String str) {
if (str.length() % 2 != 0) {
return false;
}
Stack<Character> stack = new Stack<>();
int mid = str.length() / 2;
for (int i = str.length() - 1; i >= mid; i--) {
stack.push(str.charAt(i));
}
int idx = 0;
while (!stack.isEmpty()) {
char c = stack.pop();
if (c != str.charAt(idx++)) {
return false;
}
}
return true;
}
}