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.cs
STDIN
Run
// C# program to find all the patterns of 0(1+)0 in the given string using System; public class W3CW { // @It's the driver function static public void Main (string[] args) { Console.Write("Enter the string: "); string str = Console.ReadLine(); Console.WriteLine("\nThe Number of patterns found: " + findPattern(str)); } // @This function will find the pattern static public int findPattern(string str) { char last = str[0]; int i = 1, c = 0; // c is the counter part while (i < str.Length) { if (str[i] == '1' && last == '0') { while (i < str.Length && str[i] == '1') i++; if (i < str.Length && str[i] == '0') c++; } last = i < str.Length ? str[i] : last; i++; } return c; } }
1001001001
Output
Clear
ADVERTISEMENTS