CSharp · Console
using System;
using System.Text;
using System.Collections.Generic;
public class Program
{
public static Dictionary<string, string> GoalMap = new Dictionary<string, string>()
{
{ "G", "G" },
{ "()", "o" },
{ "(al)", "al" }
};
public static string Interpret(string command) {
int i = 0, len = command.Length;
var sb = new StringBuilder();
string com = "";
while (i < len)
{
// формируем команду текущими символами
com += command[i];
if (GoalMap.ContainsKey(com))
{
sb.Append(GoalMap[com]);
com = "";
}
i++;
}
return sb.ToString();
}
public static void Main()
{
Console.WriteLine("UniLecs");
// tests
Console.WriteLine(Interpret("G()(al)")); // Goal
Console.WriteLine(Interpret("G()()()()(al)")); // Gooooal
}
}