-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP171SUMI.cpp
More file actions
41 lines (35 loc) · 816 Bytes
/
P171SUMI.cpp
File metadata and controls
41 lines (35 loc) · 816 Bytes
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
#include<bits/stdc++.h>
using namespace std;
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Ford(i, a, b) for(int i = a; i >= b; i--)
#define ll long long
#define here cout<<"I am Here"<<endl;
int const maxn = 1000000;
int const base = 1e9 + 7;
int Solution(char Str[],int n){
int res = 0;
int i = 0;
while(i < n - 1){
if(Str[i] != Str[i + 1]){
res++;
i++;
}
if(Str[i] == Str[i + 1]) i += 2;
if(i == n - 1) res++;
}
if(res > 3) return 0;
return 1;
}
int main(void){
int Test;
cin>>Test;
while(Test--){
char Str[100001];
cin>>Str;
int n = strlen(Str);
sort(Str, Str + n);
if(Solution(Str, n) == 1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}