-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mario and the Broken String
55 lines (50 loc) · 1.32 KB
/
Mario and the Broken String
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
Problem
Mario was going to gift Princess Peach a string S of even length N.
Input Format
The first line of input will contain a single integer T, denoting the number of test cases.
Each test case consists of two lines of input:
The first line of each test case contains N - the length of the initial string S.
The second line contains the string S.
Output Format
For each test case,
print YES if it is guaranteed that Mario will get the same string S irrespective of the order in which he joins the strings A and B and NO otherwise.
You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical).
INPUT
4
6
abcabc
6
abcdef
4
aaaa
4
baab
OUTPUT
YES
NO
YES
NO
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++)
{
int a=sc.nextInt();
String b=sc.next();
if(b.substring(0,a/2).equals(b.substring(a/2))){
System.out.println("YES");
}
else{
System.out.println("No");
}
}// your code goes here
}
}