Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace ReverseSentenceAndNotPunctoation
- {
- class ReverseSentence
- {
- static void Main(string[] args)
- {
- string sentense = Console.ReadLine();
- Regex words = new Regex(@"([a-zA-Z]+)");
- Regex nonWords = new Regex(@"([^a-zA-Z]+)");
- MatchCollection allWords = words.Matches(sentense);
- MatchCollection allNonWords = nonWords.Matches(sentense);
- List<string> singleWords = new List<string>();
- List<string> singleNonWords = new List<string>();
- foreach (Match word in allWords)
- {
- singleWords.Add(word.Groups[1].ToString());
- }
- foreach (Match nonWord in allNonWords)
- {
- singleNonWords.Add(nonWord.Groups[1].ToString());
- }
- StringBuilder result = new StringBuilder();
- for (int i = singleWords.Count - 1, j = 0; i >= 0; i--, j++)
- {
- result.Append(singleWords[i]);
- result.Append(singleNonWords[j]);
- }
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment