April 25

умом? умом.

Если вы это читаете, значит вы умный человек, Марк Анатольевич. Я очень стремлюсь к познанию ООП, однако раз я зашел на эту страницу, я был вынужден обратиться к помощи великих. Ыыы.

public override string Solve()
{
int counter = 0;
for (int i = 2; i < text.Length; i++)
{
if (((text[i] < 'а' || text[i] > 'я') && (text[i] < 'А' || text[i] > 'Я')) && (((text[i-2] < 'а' || text[i-2] > 'я') && (text[i-2] < 'А' || text[i-2] > 'Я'))))
{
counter += 1;
}
}
return counter.ToString();
}
}
public class Program
{
public static void Main()
{
string textous = "Проверка и тесты ура, а как же тесто, ы, б, ме, ура. Не, не";
Task a = new Task1(textous);
Console.WriteLine(a.Solve());
}
}
}

using System.Text.Json; using System.Text.Json.Serialization; using static System.Net.Mime.MediaTypeNames;

abstract class Task { protected string text = "Example"; public string Text { get => text; protected set => text = value; } public Task(string text) { this.text = text; } } class Task1 : Task { [JsonConstructor] public Task1(string text) : base(text) { } public override string ToString() { return text; } } class Task2 : Task { [JsonConstructor] public Task2(string text) : base(text) { } public override string ToString() { return "proverka"; } } class JsonTasks { public static void Write<T>(T obj, string path) { using (FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate)) { JsonSerializer.Serialize(fileStream, obj); } } public static T Read<T>(string path) { using (FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate)) { return JsonSerializer.Deserialize<T>(fileStream); } } } class Program { static void Main() { Task[] tasks = { new Task1("12345 12345"), new Task2("34567 34567") };

string root_path = @"C:\Users\b804\Documents"; string folderName = "Solution"; string task1_filename = "cw_2_task_1.json"; string task2_filename = "cw_2_task_2.json";

root_path = Path.Combine(root_path, folderName); if (!Directory.Exists(root_path)) { Directory.CreateDirectory(root_path); }

task1_filename = Path.Combine(root_path, task1_filename); task2_filename = Path.Combine(root_path, task2_filename);

if (!File.Exists(task1_filename)) { var filec = File.Create(task1_filename); filec.Close(); }

if (!File.Exists(task2_filename)) { JsonTasks.Write<Task1>(tasks[0] as Task1, task1_filename); JsonTasks.Write<Task2>(tasks[1] as Task2, task2_filename); } else { Task1 task1 = JsonTasks.Read<Task1>(task1_filename); Task2 task2 = JsonTasks.Read<Task2>(task2_filename); } Console.WriteLine(tasks[0]); Console.WriteLine(tasks[1]);

} }