Advertisement
ralka

06. Reverse Sentence

Jun 6th, 2016
208
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None
  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_Sentence
  8. {
  9.     class ReverseWordsInSentence
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string sentence = Console.ReadLine();
  14.  
  15.             char[] delimiters = { ',', '.', ':', ';', '=', '(', ')', '&', '[', ']', '"', '\'', '\\', '/', '!', '?', ' '};
  16.             string[] splitSentence = sentence
  17.                 .Split(delimiters, StringSplitOptions.RemoveEmptyEntries)
  18.                 .ToArray();
  19.  
  20.             char[] wordsSeparators = string.Join("", splitSentence).ToCharArray();
  21.  
  22.             string[] separators = sentence
  23.                 .Split(wordsSeparators, StringSplitOptions.RemoveEmptyEntries)
  24.                 .ToArray();
  25.  
  26.             int wordsIndex = splitSentence.Length - 1;
  27.             for (int i = 0; i < splitSentence.Length; i++)
  28.             {
  29.                 Console.Write(splitSentence[wordsIndex]);
  30.                 Console.Write(separators[i]);
  31.                 wordsIndex--;
  32.             }
  33.             Console.WriteLine();
  34.  
  35.         }
  36.     }
  37. }
Advertisement
RAW Paste Data Copied
Advertisement