Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace Example
- {
- internal class Program
- {
- private static void Main()
- {
- Console.Write("Введите текст: ");
- var line = Console.ReadLine();
- if (!string.IsNullOrEmpty(line))
- {
- var pattern = new Regex(@"([a-zA-Zа-яА-Я])+");
- var matches = pattern.Matches(line);
- var words = matches.Cast<Match>().Select(x => x.ToString().ToLowerInvariant()).ToList();
- var box = new List<Tuple<string, int>>();
- foreach (var word in words)
- {
- if (!box.Exists(x => x.Item1 == word))
- {
- box.Add(new Tuple<string, int>(word, 1));
- }
- else
- {
- var old = box.Find(x => x.Item1 == word);
- box.Remove(old);
- var value = old.Item2 + 1;
- box.Add(new Tuple<string, int>(word, value));
- }
- }
- foreach (var value in box)
- {
- Console.WriteLine(value.Item1 + " : " + value.Item2);
- }
- }
- else
- {
- Console.WriteLine("Пустая строка!");
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement