Advertisement
ElliasBLR

Vitaly 5

Oct 27th, 2020
755
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             /*Дана строка текста, в которой слова разделены пробелами. Необходимо:
  13.             - определить количество слов в строке;
  14.             - вывести все слова строки в порядке возрастания их длин;
  15.             - вывести все слова, начинающиеся на букву «t».
  16.              */
  17.             string tmp;
  18.  
  19.             Console.WriteLine("Введите строку :");
  20.             string text = Console.ReadLine();
  21.             Console.WriteLine("Количество слов в строке  :");
  22.             string[] words = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  23.             Console.WriteLine(words.Length);
  24.             Console.WriteLine("Все слова в порядке возрастания длин:");
  25.             for (int i = 0; i < words.Length; i++)
  26.             {
  27.  
  28.  
  29.                 for (int j = i + 1; j < words.Length; j++)
  30.                 {
  31.  
  32.                     if (words[i].Length >= words[j].Length)
  33.                     {
  34.                         tmp = words[i];
  35.                         words[i] = words[j];
  36.                         words[j] = tmp;
  37.                     }
  38.  
  39.                 }
  40.                 Console.WriteLine(words[i]);
  41.             }
  42.  
  43.             Console.WriteLine("Слова,начинающиеся на букву 't' :");
  44.             tmp = words[0];
  45.             for (int i = 0; i < words.Length; i++)
  46.             {
  47.                 if (words[i][0] == 't')
  48.                 {
  49.                     Console.WriteLine(words[i]);
  50.  
  51.                 }
  52.  
  53.             }
  54.  
  55.  
  56.  
  57.  
  58.             Console.ReadKey();
  59.  
  60.         }
  61.     }
  62. }
  63.  
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement