Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace PR4
- {
- class Program
- {
- static void Main(string[] args)
- {
- //-----------1
- Console.Write("Введите строку: ");
- string text1 = Console.ReadLine();
- text1 = Regex.Replace(text1, "[ ]+", " "); //Пользуюсь регулярными выражениями, так как недавно читал про них)
- Console.WriteLine("Строка без лишних пробелов: " + text1);
- //-----------2
- string[] textArray = text1.Split(' ');
- string maxWord = ""; /*Code protected by ZAV*/
- int maxWordCount = 0;
- foreach (var k in textArray)
- {
- if (k.Length > maxWord.Length)
- {
- maxWord = k;
- }
- else if (k == maxWord)
- {
- maxWordCount++;
- }
- }
- Console.WriteLine("Максимальное слово: \"{0}\" повторяется ({1}) раз.", maxWord, maxWordCount);
- //-----------3
- Console.Write("Введите строку: ");
- string text2 = Console.ReadLine();
- ParseBrackets(text2);
- Console.ReadLine();
- }
- static int ParseBrackets(string text)
- {
- int temp = 0;
- for (int i = 0; i < text.Length; i++)
- {
- if (text[i] == '(')
- {
- temp++;
- }
- else if (text[i] == ')')
- {
- temp--;
- }
- if (temp < 0)
- {
- Console.WriteLine("Ошибка в {0} символе", (i + 1));
- return temp;
- }
- }
- if (temp > 0)
- {
- Console.WriteLine("Ошибка. Лишние откр. скобки: {0} шт", temp);
- return -1;
- }
- Console.WriteLine("Все верно.");
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment