forked from sureshmangs/Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1499B - Binary Removals.cpp
81 lines (54 loc) · 2.03 KB
/
1499B - Binary Removals.cpp
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
/*
You are given a string s, consisting only of characters '0' or '1'. Let |s| be the length of s.
You are asked to choose some integer k (k>0) and find a sequence a of length k such that:
1=a1<a2<?<ak=|s|;
ai-1+1<ai for all i from 2 to k.
The characters at positions a1,a2,…,ak are removed, the remaining characters are concatenated without changing the order. So, in other words, the positions in the sequence a should not be adjacent.
Let the resulting string be s'. s' is called sorted if for all i from 2 to |s'| s'i-1=s'i.
Does there exist such a sequence a that the resulting string s' is sorted?
Input
The first line contains a single integer t (1=t=1000) — the number of testcases.
Then the descriptions of t testcases follow.
The only line of each testcase contains a string s (2=|s|=100). Each character is either '0' or '1'.
Output
For each testcase print "YES" if there exists a sequence a such that removing the characters at positions a1,a2,…,ak and concatenating the parts without changing the order produces a sorted string.
Otherwise, print "NO".
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
inputCopy
5
10101011011
0000
11111
110
1100
outputCopy
YES
YES
YES
YES
NO
Note
In the first testcase you can choose a sequence a=[1,3,6,9]. Removing the underlined letters from "10101011011" will produce a string "0011111", which is sorted.
In the second and the third testcases the sequences are already sorted.
In the fourth testcase you can choose a sequence a=[3]. s'= "11", which is sorted.
In the fifth testcase there is no way to choose a sequence a such that s' is sorted.
*/
#include<bits/stdc++.h>
using namespace std;
void solve() {
string s;
cin >> s;
int ones = s.find("11");
int zeros = s.rfind("00");
if (ones != -1 && zeros != -1 && ones < zeros) cout << "NO\n";
else cout << "YES\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
cin >> t;
while (t--) solve();
return 0;
}