Advertisement
Nikolcho

06. Reverse Array of Strings

Jun 2nd, 2018
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _06.Reverse_Array_of_Strings
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             string text = Console.ReadLine();
  15.             string[] reversedText = new string[text.Length];
  16.  
  17.             int lastItemOfReversedText = text.Length - 1;
  18.  
  19.             for (int index = 0; index < text.Length; index++)
  20.             {
  21.                 if (text[index] == ' ')
  22.                 {
  23.                     lastItemOfReversedText--;
  24.                 }
  25.                 else
  26.                 {
  27.                     reversedText[lastItemOfReversedText] += text[index];                    
  28.                 }
  29.             }
  30.  
  31.             for (int index = 0; index < text.Length; index++)
  32.             {
  33.                 Console.Write($"{string.Join(" ", reversedText[index])} ");
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement