Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.4 kB
2
Indexable
Never
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;
int main()
{
    int j, test;
    cin >> test;
    for (j = 0; j < test; j++)
    {
        string str;
        int i, flag = 0, pos, one = 0, count = 0;
        cin >> str;
        int strlen = str.length();

        for (i = 0; i < strlen; i++)
        {
            if (str[i] == '1')
            {
                pos = i;
                flag = 0;
                break;
            }
            else
            {
                pos = strlen;
                flag = 1;
            }
        }

        for (i = 0; i < str.length(); i++)
        {
            if (str[i] == '1')
            {
                one++;
            }
        }
        //000111
        for (i = pos; i < strlen; i++)
        {
            if (str[i] == '0')
            {
                if (one == count)
                {
                    flag = 0;
                    break;
                }
                else
                {
                    flag = 1;
                    break;
                }
            }
            count++;
        }

        if (flag == 1)
        {
            cout << "NO" << endl;
        }
        else
        {
            cout << "YES" << endl;
        }
    }
    return 0;
}