Pergunta de entrevista da empresa Microsoft

how to reverse words in a string preserving the formatting

Respostas da entrevista

Sigiloso

11 de out. de 2010

google it

Sigiloso

24 de nov. de 2010

public void ReverseWords(StringBuilder sb) { if (sb == null) { return ; } String tempStr = ""; int start = -1; int end = -1; //"My na" for (int i = sb.Length -1; i >= 0; i--) { if (sb[i] == ' ') { if (end != -1) { start = i + 1; // end = 4 // start = 3 while (start <= end) { tempStr = tempStr + sb[start]; start++; } start = -1; end = -1; } tempStr = tempStr + sb[i]; } else { if (end == -1) { end = i; } } } if (end != -1) { for (int i = 0; i <= end; i++) { tempStr = tempStr + sb[i]; } } Console.WriteLine(tempStr); }