2021-02-28

A - Row 补题

You’re given a row with n chairs. We call a seating of people “maximal” if the two following conditions hold:

There are no neighbors adjacent to anyone seated.
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 n≠2).

The first line contains a single integer n (1≤n≤1000) — the number of chairs.

The next line contains a string of n characters, each of them is either zero or one, describing the seating.

Input
3
101
Output
Yes
Input
4
1011
Output
No
Input
5
10001
Output
No

#include <stdio.h>
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int i=0;
		char a[1000];
		char b[1000];

//		}
		scanf("%s",&b);
		getchar();
		int k=1;
		for(i=0;i<n;i++){
			a[k]=b[i];
			k++;
		}
		a[0]='0';
		a[n+1]='0';
		int m=0;
		n=n+2;
		for(i=1;i<n-1;i++){
			if(a[i]=='0'&&a[i-1]=='0'&&a[i+1]=='0'){
				m++;
			}
		}
		for(i=1;i<n;i++){
			if(a[i]=='1'&&a[i-1]=='1'){
				m++;
			}
		}
		if(m==0){
			printf("Yes\n");
		}
		if(m!=0){
			printf("No\n");
		}
	}
	return 0;
} 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值