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;
}