Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
reverse words in astring
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace CodingAlgorithms { public static class ReverseWords { //Reverse words in a string public static string Reverse(string s) { string result = ""; Stack temp = new Stack(); s = s.Trim(); //Remove extra white space between characters while (s.Contains(" ")) s = s.Replace(" ", " "); //Store each word on the Stack foreach (string x in s.Split(' ')) temp.Push(x); //Add each word to the result string in reverse order since a stack is a FIFO data structure while (temp.Count != 0) result += temp.Pop() + " "; return result.Trim(); } } }
run
|
edit
|
history
|
help
0
Main 4-3
Project Euler Problem 6
Upgrade
System Convert
числата от 1 до 20
Cotton Farm v: (0.0.0.002)
DataTables Left Join
asxasxd
2
Deadlock Example