C++ Online Compiler
Example: C++ program to find all the patterns of 0(1+)0 in the given string
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ program to find all the patterns of 0(1+)0 in the given string #include <bits/stdc++.h> #include <cstring> using namespace std; // @This function will find the pattern int findPattern(char str[]) { char last = str[0]; int i = 1, c = 0; // c is the counter part while (i < strlen(str)) { if (str[i] == '1' && last == '0') { while (str[i] == '1') i++; if (str[i] == '0') c++; } last = str[i]; i++; } return c; } // @It's the driver function int main() { char str[50]; cout << "Enter the string: "; cin >> str; cout << "\nThe Number of patterns found: " << findPattern(str) << "\n"; return 0; }
1001001001
Output
Clear
ADVERTISEMENTS