Thursday, 4 August 2016

Beautiful Binary String Hacker Rank Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() {

 int n,cnt = 0;
 string str;
 cin >> n;
 cin >> str;
 for(int i = 0; i < n;){
        if(str[i] == '0' && str[i+1] == '1' && str[i+2] == '0'){
            cnt++;
            i+=3;
        }
        else i++;
 }
 cout << cnt << endl;
 return 0;
}

No comments:

Post a Comment