mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-10-29 22:17:23 +01:00
feat(solutions): add look-and-say-sequence-conway/cs/function
This commit is contained in:
parent
46e6f2d7ca
commit
b3fb594865
@ -0,0 +1,3 @@
|
||||
# look-and-say-sequence-conway/cs/function
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 30 November 2021.
|
@ -0,0 +1,27 @@
|
||||
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() + line[index];
|
||||
index += numberOfAppearances - 1;
|
||||
}
|
||||
Console.WriteLine(result);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user