-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHappyLadybugs.java
More file actions
82 lines (79 loc) · 1.17 KB
/
HappyLadybugs.java
File metadata and controls
82 lines (79 loc) · 1.17 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.io.*;
import java.util.Scanner;
class HappyLadybugs
{
public static void main(String[]args)throws IOException
{
BufferedReader venki=new BufferedReader(new InputStreamReader(System.in));
int t,i,j,f=0,c=0,temp=0,flag=0,k=0,p=0;
int n;int a[]=new int[10000],A[]=new int[10000];
String ch[]=new String[10000];
int g=Integer.parseInt(venki.readLine());
for(t=0;t<g;t++)
{
flag=0;k=0;c=0;
n=Integer.parseInt(venki.readLine());
String str=venki.readLine();
for(i=0;i<n;i++)
{
a[i]=(int)str.charAt(i);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<n;i++)
{
c++;
A[i]=a[i];
}
for(i=0;i<c;i++)
{
f=0;
for(j=0;j<c;j++)
{
if(A[i]==A[j])
{
f++;
}
}
if(f<2)
{
flag=1;
}
if(f>=2)
{
k=1;
}
}
if(a[0]=='_')
{
ch[t]="YES";
}
if(p!=1)
{
ch[t]="NO";
}
if(flag!=1 && k==1)
{
ch[t]="YES";
}
else if(flag==1)
{
ch[t]="NO";
}
}
for(i=0;i<g;i++)
{
System.out.println(ch[i]);
}
}
}