Bear and Segment 01
All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Bear Limak has a string S. Each character of S is a digit '0' or '1'.
Help Limak and check if all the '1' digits form a single non-empty segment (consecutive subsequence) in the string. For each test case, print "YES" or "NO" accordingly.
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The only line of each test case contains one string S, consisting of digits '0' and '1' only.
For each test case, output a single line containing the answer — "YES" if all the '1' digits form a single non-empty segment, and "NO" otherwise. Don't print the quotes.
- 1 ≤ T ≤ 10
- 1 ≤ |S| ≤ 105 (here, |S| denotes the length of S)
- Subtask #1 (50 points): 1 ≤ |S| ≤ 50
- Subtask #2 (50 points): Original constraints.
Input: 6 001111110 00110011 000 1111 101010101 101111111111 Output: YES NO NO YES NO NO
The answer is "YES" for strings 001111110 and 1111.
The answer is "NO" for 00110011 because the '1' digits form two disjoint segments (while they should all be consecutive, with no '0' digits between them).
The answer is "NO" for 000 because the segment formed by the '1' digits must be non-empty (as written in the statement).
|Tags||cakewalk, errichto, linear-search, ltime47|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.