Alex’s Game(I)

来源:互联网 发布:江西省网络作家协会 编辑:程序博客网 时间:2024/06/04 01:24
F - Alex’s Game(I)
Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

Alex likesto play with one and zero!One day he gets an empty string.So our cute boy wants to add one and zero in it. Every time he will add ‘01’in the string at any position and then get a new string.For example:if the string is “01” now ,he can get “0101” or “0011,Now give you a string that is Alex has get,you need to answer whether the string is legal?

Input

First is a integer n(n<=100) 
Next contains n lines .Every line is a string whose legth is no more than 1000.

Output

For each case output "YES" in a single line if it’s legal. 
Or you need to output “NO”;

Sample Input

3010101100011

Sample Output

YESNOYES

Hint

这个题很简单,对于字符串里的所有的0,只要0前面的1的个数不会大于0的个数就可以说明所有插入的字符串都是01排列了。
#include<stdio.h>#include<string.h>int main(){    int n;    char a[1005];    scanf("%d",&n);    while(n--)    {        int flag=0;        scanf("%s",a);        for(int j=0; j<strlen(a); j++)        {            if(a[j]=='0')            {                int sum1=0,sum2=0;                for(int k=0; k<j; k++)                {                    if(a[k]=='1')                        sum1++;                    else                        sum2++;                }                if(sum1>sum2)                {                    printf("NO\n");                    flag=1;                    break;                }            }        }        if(!flag)            printf("YES\n");    }    return 0;}


2 0
原创粉丝点击