-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHappy Ladybugs
76 lines (73 loc) · 1.87 KB
/
Happy Ladybugs
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
#include<stdio.h>
#include<string.h>
int main(){
char str[100];
int _count=0,i,n,temp,t,count[26],ans=0;
for(i=0;i<26;i++){
count[i]=0;
}
scanf("%d",&t);
while(t--){
scanf("%d",&n);
scanf("%s",str);
for(i=0;i<n;i++){
//scanf("%c",str[i]);
if(str[i]=='_'){
_count++;
}
else{
temp = str[i] - 65;
count[temp]++;
}
}
if(_count == 0){
for(i=0;i<n;i++){
temp = str[i];
if(count[temp - 65] == 1){
ans=0;
break;
}
else if(i==0 && (str[i] != str[i+1])){
//if(str[i] != str[i-1]){
ans=0;
break;
//}
}
else if(i==n-1 && (str[i] != str[i-1])){
//if(str[i] != str[i+1]){
ans=0;
break;
//}
}
else if((i!=0) && (i!=n-1) && (str[i-1]!=str[i]) && (str[i+1]!=str[i])){
ans=0;
break;
}
ans = 1;
}
if(ans)printf("YES\n");
else printf("NO\n");
}
else if(_count>0){
for(i=0;i<n;i++){
temp = str[i];
if(temp == 95){
ans=1;
continue;
}
if(count[temp - 65] <= 1){
ans=0;
break;
}
ans=1;
}
if(ans)printf("YES\n");
else printf("NO\n");
}
for(i=0;i<26;i++){
count[i] = 0;
}
ans=0;
_count=0;
}
}