codeforces982A

题意 

给你个排列    10001

满足下列条件输出yes  否则输出no

1、不能有两个1相连

2、当点排列不能再加入1

全0判断一下

开头判断一下

结尾判断一下

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
char str[1005];
int main()
{
    int n,i,pre,cnt = 0;
    bool flag = false;
    scanf("%d",&n);
    scanf("%s",str);
    if(n == 1)
    {
        if(str[0] == '1')
            printf("Yes\n");
        else
            printf("No\n");
        return 0;
    }
    pre = -2;
    if(str[0] == '1')
    {
        pre = 0;
        flag = true;
    }
    for(i=1;i<strlen(str);++i)
    {
        if(str[i] == '1')
        {
            flag = true;
            if((i-pre!=2) && (i-pre!=3))
            {
                printf("No\n");
                return 0;
            }
            pre = i;
        }
    }
    i--;
    if(str[i] == '0')
    {
        if(i - pre == 2 || i-pre == 3)
            flag = false;
    }
    if(flag)
        printf("Yes\n");
    else
        printf("No\n");
}

猜你喜欢

转载自www.cnblogs.com/mltang/p/9066152.html
今日推荐