Advertisement
ElliasBLR

Tihon lab5

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