Advertisement
ElliasBLR

Volchok 5

Oct 27th, 2020
849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 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.             - найти самое короткое слово в строке, которое заканчивается на букву «а»;
  16.             - вывести все слова, которые заканчиваются на букву «а».
  17.  
  18.  */
  19.             string min;
  20.  
  21.             Console.WriteLine("Введите строку :");
  22.             string text = Console.ReadLine();
  23.             Console.WriteLine("Количество слов в строке  :");
  24.             string[] words = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  25.             Console.WriteLine(words.Length);
  26.             Console.WriteLine("Самое короткое слово в строке,которое заканчивается на букву 'a': ");
  27.             for (int i = 0; i < words.Length; i++)
  28.             {
  29.                 if (words[i][words[i].Length - 1] == 'а')
  30.                 {
  31.                     min = words[i];
  32.                     for (int j = i+1; j<words.Length;j++)
  33.                     {
  34.                         if(min.Length > words[j].Length)
  35.                         {
  36.                             if(words[j][words[j].Length - 1] == 'a')
  37.                             {
  38.                                 min = words[j];
  39.  
  40.                             }
  41.                         }
  42.                     }
  43.                     Console.WriteLine(min);
  44.                     break;
  45.                 }
  46.             }
  47.            
  48.             Console.WriteLine("Слова,заканчивающиеся на букву 'а' :");
  49.            
  50.             for (int i = 0; i < words.Length; i++)
  51.             {
  52.                 if (words[i][words[i].Length-1] == 'а')
  53.                 {
  54.                     Console.WriteLine(words[i]);
  55.  
  56.                 }
  57.  
  58.             }
  59.  
  60.  
  61.  
  62.  
  63.             Console.ReadKey();
  64.  
  65.         }
  66.     }
  67. }
  68.  
  69.  
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement