Source Code
#include<iostream>
using namespace std;

 int main (){
  string name;
  cin>>name;
  int size=0;
  int nh=0;
  int mid;
  for(int i=0; name[i]!='\0';i++){
    size++;
  }
  if(name[0]==0&&size==1){
    cout<<0;
    exit(0);
    }
  if(name[0]==1&&size==1)
  {
    cout<<'1';
    exit(0);
  }
  for(int i=0;i<size;i++){
      if(name[i]=='1')nh++;
  }
  if(size==2){ 
    cout<<nh;
  }
  else{
   for(int i=1;i<size-1;i++){
    if(name[i]=='0'&&name[i+1]=='1'&&name[i-1]=='1')
      nh++;
    }
   cout<<nh;
  }
  return 0;

    
 }
Copy
Japanese holidays samihamad
GNU G++17
4 ms
1.1 MB
Accepted