I made a solution that gave me the value of the longest continuous sequence of characters, but how would I need to modify it to specify I need the longest continuous sequence of the character C? Or would I need a whole new block of code completely?
using System;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;
using System.Text;
namespace CarCounting
{
internal class Program
{
static void Main(string[] args)
{
CarCounting newSequence = new CarCounting();
Console.WriteLine(newSequence.longest("CCMCCCCLLCCC")); //executes the function
}
}
public class CarCounting
{
public CarCounting()
{
}
public int longest(string mySequence)
{
//turns the argument into an array
char[] charC = new char[mySequence.Length];
for (int i = 0; i < mySequence.Length; i++)
{
charC[i] = mySequence[i];
}
int charCcount = 0;
int length = charC.Length;
//compares the values in the array
for(int i = 0; i < length; i++)
{
int currentcount = 1;
for (int j = i + 1; j < length; j++)
{
if (charC[i] != charC[j])
break;
currentcount++;
}
if (currentcount > charCcount)
{
charCcount = currentcount;
}
}
return charCcount;
}
}
}