Created
June 6, 2016 08:44
-
-
Save Nikola-Andreev/ec9eb12a03e8a64ac8000b83f0149c01 to your computer and use it in GitHub Desktop.
6.Reverse words in sentence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Numerics; | |
using System.Globalization; | |
using System.Text.RegularExpressions; | |
using System.Threading; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string text = Console.ReadLine(); | |
char[] separators = { '.', ',', ':', ';', '=', '(', ')', '&', '[', ']', '\"', '\'', '\\', '/', '!', '?', ' ' }; | |
List<string> list = text.Split(separators, StringSplitOptions.RemoveEmptyEntries).ToList(); | |
list.Reverse(); | |
List<string> tempList = new List<string>(list); | |
tempList.Sort((e1, e2) => e2.Length.CompareTo(e1.Length)); | |
List<string> sep = text.Split(tempList.ToArray(), StringSplitOptions.RemoveEmptyEntries).ToList(); | |
for (int i = 0; i < list.Count; i++) | |
{ | |
Console.Write(list[i] + sep[i]); | |
} | |
Console.WriteLine(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment