Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nikola-Andreev/ec9eb12a03e8a64ac8000b83f0149c01 to your computer and use it in GitHub Desktop.
Save Nikola-Andreev/ec9eb12a03e8a64ac8000b83f0149c01 to your computer and use it in GitHub Desktop.
6.Reverse words in sentence
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