Advertisement
Graf_Rav

Untitled

May 17th, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     int n;
  7.     cin>>n;
  8.    
  9.     if(n==1 ){
  10.         char a;
  11.         cin>>a;
  12.         if(a=='1'){
  13.             cout<<"Yes";
  14.         }
  15.         else{
  16.             cout<<"No";
  17.         }
  18.     }
  19.     else{
  20.         char a;
  21.         char b;
  22.         int k=1;
  23.         for(int i=0;i<n;i++){
  24.             cin>>b;
  25.             if(b=='0'){
  26.                 k++;
  27.                 if(k==3){
  28.                     cout<<"No";
  29.                     return 0;
  30.                 }
  31.             }
  32.             else{
  33.                 k=0;
  34.             }
  35.             if(i>=1){
  36.                 if(a==b && a=='1'){
  37.                     cout<<"No";
  38.                     return 0;
  39.                 }
  40.             }
  41.             if(i!=n-1){
  42.                 a=b;
  43.             }
  44.         }
  45.         if(a==b && a=='0'){
  46.             cout<<"No";
  47.             return 0;
  48.         }
  49.         cout<<"Yes";
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement