Created
October 1, 2021 00:30
-
-
Save unilecs/e13c78b00563a4ddef89cf1faa140c0f to your computer and use it in GitHub Desktop.
Залипание клавиш
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
public static bool IsLongPressedString(string origin, string typed) { | |
int oLen = origin.Length; | |
int tLen = typed.Length; | |
// указатель на символ в name | |
// после прохода по typed мы должны встретить все символы из origin | |
int k = 0; | |
// проходим по набранной строке typed | |
for (int i = 0; i < tLen; i++) | |
{ | |
// если текущие символы равны, увеличиваем наш указатель k | |
if (k < oLen && origin[k] == typed[i]) | |
{ | |
k++; | |
} | |
// иначе проверяем, что предыдуший набранный символ 'залип': | |
// если это не так и мы встретили другой символ, | |
// значит набранная строка не совпадает с origin | |
else if (i == 0 || typed[i] != typed[i - 1]) | |
{ | |
return false; | |
} | |
} | |
// мы прошли по всем символам имени origin ?! | |
return k == oLen; | |
} | |
public static void Main() | |
{ | |
Console.WriteLine("UniLecs"); | |
// Tests | |
Console.WriteLine(IsLongPressedString("albert", "albert")); // true | |
Console.WriteLine(IsLongPressedString("albert", "aaalberrt")); // true | |
Console.WriteLine(IsLongPressedString("lee", "lle")); // false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment