using System;
using System.Linq;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
// --- ЗАДАНИЯ 1-8 (Базовая работа со строками) ---
string inputStr = "10110 256.42, 88? 123 456, 7. Привет, мир!";
Console.WriteLine("--- Базовые задачи ---");
// 1. Посчитать нули и единицы
Console.WriteLine($"1. Нулей: {inputStr.Count(c => c == '0')}, Единиц: {inputStr.Count(c => c == '1')}");
// 2. Количество слов
Console.WriteLine($"2. Слов: {inputStr.Split(new[] { ' ', ',', '.', '!' }, StringSplitOptions.RemoveEmptyEntries).Length}");
// 3. Знаки препинания
Console.WriteLine($"3. Знаков препинания: {inputStr.Count(char.IsPunctuation)}");
// 4. Вывести только цифры
Console.Write("4. Цифры: ");
foreach (char c in inputStr) if (char.IsDigit(c)) Console.Write(c);
// 5. Количество четных чисел (из строки с пробелами)
string numStr = "12 33 44 55 60";
int evenCount = numStr.Split(' ').Select(int.Parse).Count(n => n % 2 == 0);
Console.WriteLine($"\n5. Четных чисел: {evenCount}");
// 6. Поменять местами символы с четными и нечетными индексами
char[] arr = "abcdef".ToCharArray();
for (int i = 0; i < arr.Length - 1; i += 2)
(arr[i], arr[i + 1]) = (arr[i + 1], arr[i]);
Console.WriteLine($"6. Перестановка: {new string(arr)}");
// 7-8. Работа с русскими буквами
string ruText = "Привет, мир! Testing 123";
var ruLetters = ruText.Where(c => c >= 'а' && c <= 'я' || c >= 'А' && c <= 'Я');
Console.WriteLine($"7. Русских строчных букв: {ruText.Count(c => c >= 'а' && c <= 'я')}");
Console.WriteLine($"8. Только русские строчные: {new string(ruText.Where(c => c >= 'а' && c <= 'я').ToArray())}");
// --- ЗАДАНИЯ 9+ (Регулярные выражения) ---
string contacts = @"
Иван Петров, email: ivan.petrov@gmail.com, телефон: +7-999-123-45-67
Анна Смирнова, email: anna_smirnova@mail.ru, телефон: +7 (912)-555-88-99
John Smith, email: john.smith@company.com, телефон: +1-202-555-0173";
Console.WriteLine("\n--- Части по регулярным выражениям ---");
// Часть 1: Email
Console.WriteLine("Часть 1: Email адреса:");
foreach (Match m in Regex.Matches(contacts, @"[\w.-]+@[\w.-]+\.\w+")) Console.WriteLine(m.Value);
// Часть 2: Телефоны
Console.WriteLine("\nЧасть 2: Телефоны:");
foreach (Match m in Regex.Matches(contacts, @"\+[\d\s()-]+")) Console.WriteLine(m.Value);
// Часть 3: Фильтрация gmail
Console.WriteLine("\nЧасть 3: Только Gmail:");
foreach (Match m in Regex.Matches(contacts, @"[\w.-]+@gmail\.com")) Console.WriteLine(m.Value);
// Часть 4: Замена
Console.WriteLine("\nЧасть 4: Маскировка телефонов:");
Console.WriteLine(Regex.Replace(contacts, @"\+[\d\s()-]+", "***PHONE***"));
// Часть 5: Структурированный вид
Console.WriteLine("\nЧасть 5: Структура:");
string pattern = @"(?<name>.+), email: (?<email>[\w.-]+@[\w.-]+\.\w+), телефон: (?<phone>\+[\d\s()-]+)";
foreach (Match m in Regex.Matches(contacts, pattern))
{
Console.WriteLine($"{m.Groups["name"].Value.Trim()} | {m.Groups["email"].Value} | {m.Groups["phone"].Value}");
}
}
}