Advertisement
Guest User

Untitled

a guest
May 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. static void Main(string[] args)
  2.         {
  3.             string input = "привет коля пошли бухать";
  4.  
  5.             MaxFind(input);
  6.         }
  7.  
  8.  
  9.         static void MaxFind(string text)
  10.         {
  11.             string[] str = text.Split(' '); // Разбиваем строку разделительными символами
  12.  
  13.             var maxLength = GetMaxLengthString(str);
  14.  
  15.             for (int i = 0; i < str.Length; i++)
  16.             {
  17.                 if (str[i].Length == maxLength)
  18.                 {
  19.                     Console.Write(str[i] + " ");
  20.                 }
  21.             }
  22.         }
  23.  
  24.  
  25.         private static int GetMaxLengthString(string[] str)
  26.         {
  27.             if (str.Length == 0) return 0;
  28.            
  29.             var maxLength = str[0].Length;
  30.             for (int i = 1; i < str.Length; i++)
  31.             {
  32.                 if (str[i].Length > maxLength)
  33.                 {
  34.                     maxLength = str[i].Length;
  35.                 }
  36.             }
  37.  
  38.             return maxLength;
  39.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement