using System.Collections.Generic;
private static string ReverseString(string chunkString){
int strLength = chunkString.Length;
StringBuilder tmpSB = new StringBuilder();
for(var i = strLength - 1; i >= 0; i--){
tmpSB.Append(chunkString[i]);
private static string Solve(string A)
int strLength = A.Length;
StringBuilder reversedString = new StringBuilder();
string fullReverseStr = Program.ReverseString(A);
StringBuilder chunkSB = new StringBuilder();
for(var j = 0; j < strLength; j++){
if(j == 0 && fullReverseStr[j] == ' ') {
fullReverseStr.Remove(0, 1);
}else if(fullReverseStr[j] == ' '){
string tmpRes = Program.ReverseString(chunkSB.ToString());
reversedString.Append(tmpRes);
reversedString.Append(' ');
chunkSB = new StringBuilder();
chunkSB.Append(fullReverseStr[j].ToString());
string tmpRes = Program.ReverseString(chunkSB.ToString());
reversedString.Append(tmpRes);
return reversedString.ToString();
public static void Main()
string strToReverse = "crulgzfkif gg ombt vemmoxrgf qoddptokkz op xdq hv ";
string afterReverse = Program.Solve(strToReverse);
Console.WriteLine("After Sorting:" + afterReverse);