1
0
This commit is contained in:
Debug_pro
2026-02-12 01:01:44 +03:00
commit 43d7845cf1
23 changed files with 1353 additions and 0 deletions

44
Parsers.cs Normal file
View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab
{
internal class Parsers
{
public static bool TryParseDouble(string? s, out double val) => double.TryParse((s ?? "").Trim().Replace(",", "."), out val);
public static bool TryParseInt(string? s, out int val) => int.TryParse((s ?? "").Trim(), out val);
public static bool TryParseDoubleArray(string? s, out double[] vals, out string err)
{
vals = Array.Empty<double>();
err = "";
if (string.IsNullOrEmpty(s) || string.IsNullOrEmpty(s)) {
err = "Пустой ввод. Введите числа, разделяя их пробелами/запятыми/точкой с запятой.";
return false;
}
string[] parts = s.Split(new[] { ' ', '\t', '\n', '\r', ',', ';' });
List<double> list = new List<double>();
for (int i = 0; i < parts.Length; i++)
{
if (!TryParseDouble(parts[i], out double val))
{
err = $"Вронгаешь элемент! [ #{i + 1}: «{parts[i]}» ]";
return false;
}
list.Add(val);
}
vals = list.ToArray();
return true;
}
}
}