Row

题目链接:http://codeforces.com/contest/982/problem/A
A. Row
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You're given a row with n

chairs. We call a seating of people "maximal" if the two following conditions hold:

  1. There are no neighbors adjacent to anyone seated.
  2. It's impossible to seat one more person without violating the first rule.

The seating is given as a string consisting of zeros and ones (0

means that the corresponding seat is empty, 1

— occupied). The goal is to determine whether this seating is "maximal".

Note that the first and last seats are not adjacent (if n2

).

Input

The first line contains a single integer n

( 1n1000

) — the number of chairs.

The next line contains a string of n

characters, each of them is either zero or one, describing the seating.

Output

Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".

You are allowed to print letters in whatever case you'd like (uppercase or lowercase).

Examples
Input
Copy
3
101
Output
Copy
Yes
Input
Copy
4
1011
Output
Copy
No
Input
Copy
5
10001
Output
Copy
No
Note

In sample case one the given seating is maximal.

In sample case two the person at chair three has a neighbour to the right.

In sample case three it is possible to seat yet another person into chair three.

题目大意    :就是给一个字符串,然后判断一下1和0是不是相互挨着

解题思路:从第一个开始跑,每一次跑判断这个的前一个和后一个与当前这个是不是有矛盾。

代码如下:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    char s[1004];
    cin>>s+1;
    int flag=1;
    for(int i=1; i<=n; i++)
    {
        if(s[i]=='1')
        {
            if((s[i-1]=='1'&&i!=1)||(s[i+1]=='1'&&i!=n))
                flag=0;
        }
        else
        {
            if((s[i-1]=='0'||i==1)&&(s[i+1]=='0'||i=n))
                flag=0;
        }
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;

}

需要注意的是:当某一个座位是0的时候,之后满足这个座位的前面和后面都是0时才判定不符合。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值