题解 | 01序列

01序列

https://www.nowcoder.com/practice/b0c948dbe577485598b982a430d65c39

#include <stdio.h>
int main() 
{
    int n,t,count=0,print=0;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    scanf("%d",&t);
    for(int j=0;j<n;j++)
    {
        if(count>=3&&(j<n-1&&a[j+1]==1))
        {
            if(count%2==0)
            {
                print+=count/2-1;
            }
            else 
            {
                print+=count/2;
            }
            
        }
        else if(count>=3&&j==n-1&&a[j]==0)
        {
            count++;
            if(count%2==0)
            {
                print+=count/2-1;
            }
            else 
            {
                print+=count/2;
            }
            break;
        }
        else if(count>=3&&j==n-1&&a[j]==1)
        {
            if(count%2==0)
            {
                print+=count/2-1;
            }
            else 
            {
                print+=count/2;
            }
            break;
        }
        if(a[j]==0)
        {
            count++;
            continue;
        }
        else
        {
            count=0;
            continue;
        }
    }
    if(t<=print)
    {
        printf("true");
    }
    else
    {
        printf("false");
    }
    return 0;
}

全部评论

相关推荐

01-30 16:13
浙江大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务