Advertisement
ElliasBLR

lab5 OAIP

Sep 27th, 2020
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 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.             string tmp;
  13.             Console.WriteLine("Введите строку :");
  14.             string text = Console.ReadLine();
  15.             Console.WriteLine("Количество слов в строке  :");
  16.             string[] words = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  17.             Console.WriteLine(words.Length);  
  18.             Console.WriteLine("Слова с чётным количеством букв:");
  19.             foreach (string word in words)
  20.             {
  21.                 if (word.Length % 2 == 0)
  22.                 {
  23.                     Console.WriteLine(word);
  24.                 }
  25.             }
  26.             Console.WriteLine("Строка в обратном порядке:");
  27.  
  28.             for (int i = 0; i < words.Length; i++)
  29.             {
  30.                 if (words[i] == words[words.Length - i - 1])
  31.                 {
  32.                     break;
  33.                 }
  34.                 tmp = words[i];
  35.                 words[i] = words[words.Length - i - 1];
  36.                 words[words.Length - i - 1] = tmp;
  37.             }
  38.             foreach (string word in words)
  39.             {
  40.                 Console.Write(word + " ");
  41.             }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.             Console.ReadKey();
  50.  
  51.         }
  52.        
  53.         }
  54.     }
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement