Advertisement
ElliasBLR

KS5

Oct 7th, 2020
1,760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2. class HelloWorld
  3. {
  4.     static void Main()
  5.     {
  6.         int n = 1;
  7.        
  8.         Console.WriteLine("Введите строку :");
  9.         string text = Console.ReadLine();
  10.         Console.WriteLine("Количество слов в строке  :");
  11.         string[] words = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  12.         Console.WriteLine(words.Length);
  13.         string ex = words[0];
  14.         for (int i = 1; i < words.Length; i++)
  15.         {
  16.             if (ex.Length > words[i].Length)
  17.             {
  18.                 ex = words[i];
  19.                 n = 1;
  20.             }
  21.             else if (ex.Length == words[i].Length)
  22.             {
  23.                 n += 1;
  24.             }
  25.  
  26.         }
  27.         Console.WriteLine("Количество слов с минимальной длинной в строке : " + n);
  28.        
  29.         Console.WriteLine("Слова,которые начинаются с буквы 'c' : ");
  30.         foreach (string word in words)
  31.         {
  32.             if (word[0] == 'с')
  33.             {
  34.                 Console.WriteLine(word);
  35.             }
  36.         }
  37.         Console.ReadKey();
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement