using System;
using static System.Math;
internal struct Vector : IComparable<Vector>
{
public const double DELTA = 0.0000001;
public double Length { get; private set; }
public Vector(int x, int y) => Length = x * x + y * y;
public static Vector Parse(string input)
{
var coords = input.Split();
if (coords.Length < 2)
throw new ArgumentException("Incorrect vector");
return new Vector(int.Parse(coords[0]), int.Parse(coords[1]));
}
public int CompareTo(Vector other)
{
if (Length < other.Length)
return -1;
else if (Length > other.Length)
return 1;
return 0;
}
}
static string GetReplacedString(string line, string initial, string final)
{
var index = line.IndexOf(initial);
var chars = line.ToList();
if (index < 0) return line;
chars.RemoveRange(index, initial.Length);
chars.InsertRange(index, final);
line = new string(chars.ToArray());
return GetReplacedString(line, initial, final);
}
static string GetReplacedString(string line, string initial, string final)
{
while (line.Contains(initial))
{
var index = line.IndexOf(initial);
var chars = line.ToList();
if (index < 0) return line;
chars.RemoveRange(index, initial.Length);
chars.InsertRange(index, final);
line = new string(chars.ToArray());
}
return line;
}
using System.Linq;
using System;
internal sealed class ReplacedString
{
public string FinalString { get; set; }
public ReplacedString(string line, string initial, string final) =>
FinalString = Solve(line, initial, final);
public override string ToString() => FinalString;
private static string Solve(string line, string initial, string final)
{
var (borders, chars) = (GetSubarrayBorders(line, initial), line.ToCharArray());
if (borders.Length == 0)
return new string(chars);
return Solve(
new string(
chars[0..borders[0]]
.Concat(final.ToCharArray())
.Concat(chars[borders[1]..chars.Length])
.ToArray()
), initial, final
);
}
private static int[] GetSubarrayBorders(string line, string subline)
{
var (chars, x) = (line.ToCharArray(), 0);
while (x < chars.Length)
{
if (chars[x] == subline[0])
{
var status = true;
for (var y = 1; y < subline.Length; y++)
{
if (chars[x + 1] == subline[y]) x++;
else { status = false; break; }
}
if (status) return new[] { x - subline.Length + 1, x + 1 };
}
x++;
}
return Array.Empty<int>();
}
}