-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
46 lines (37 loc) · 1.14 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
namespace PersonalTasks
{
class Program
{
public static void Main(string[] args)
{
var inputValues = Console.ReadLine().Split(",",StringSplitOptions.RemoveEmptyEntries);
string inputString = inputValues[0];
int limit = int.Parse(inputValues[1]);
Console.WriteLine(stringReduction(inputString,limit));
}
public static string stringReduction(string inputString, int limit)
{
var outputString = "";
int length = 0;
//aabbaa (1) => aba
//aaab (2) => aab
for (int i = 0; i < inputString.Length; i++)
{
if ((i > 0) && (inputString[i] == inputString[i - 1]))
{
length++;
}
else
{
length = 0;
}
if (length < limit)
{
outputString += inputString[i];
}
}
return outputString;
}
}
}