1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-12-08 00:45:29 +01:00
programming-challenges/challenges/look-and-say-sequence-conway/solutions/cs/function/Solution.cs

28 lines
787 B
C#
Raw Normal View History

using System;
namespace Solution
{
class Program
{
static void Main()
{
string line = Console.ReadLine();
string result = "";
for (int index = 0; index < line.Length; index++)
{
int numberOfAppearances = 0;
char valueToSearch = line[index];
int iteration = index;
while (iteration < line.Length && line[iteration] == valueToSearch)
{
numberOfAppearances += 1;
iteration++;
}
result = result + numberOfAppearances.ToString() + valueToSearch;
index += numberOfAppearances - 1;
}
Console.WriteLine(result);
}
}
}