Reverse word of full sentence

后端 未结 16 1893
眼角桃花
眼角桃花 2020-12-06 20:04

I want to print string in reverse format:

Input: My name is Archit Patel

Output: Patel Archit is name My.

I\'ve tied the

16条回答
  •  伪装坚强ぢ
    2020-12-06 20:41

            string s = "this is a test";
    
            string[] words = s.Split(' ');
            StringBuilder sb = new StringBuilder();
    
            for (int i = words.Length - 1; i >= 0; i--)
            {
                for (int j = words[i].Length -1; j >= 0;j--)
                {
                    sb.Append(words[i][j]);
                }
                sb.Append(" ");
            }
    
            Console.WriteLine(sb);
    

提交回复
热议问题