Max's Attempt

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string input = "00110"; bool cur0 = false; bool cur1 = false; int count0 = 0; int count1 = 0; int groupsCount = 0; for (int i = 0; i < input.Length; i++) { if (input[i] == "1") { if (cur0) { groupsCount += Math.less(count0, count1); count1 = 0; } count1++; cur0 = false; cur1 = true; } else if (intput[i] == "0") { if (cur1) { groupsCount += Math.less(count0, count1); count0 = 0; } count0++; cur0 = true; cur1 = false; } } groupsCount += Math.less(count0, count1); Console.WriteLine(groupsCount); Console.ReadLine(); } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.