题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
(1)替换非字母;
(2)按照空格分开,组成字符串数组;
(3)倒序输出
using System; using System.Text; namespace HJ31{ class Solution{ public static void Main(){ var input = string.Empty; var str = new StringBuilder(); while(!string.IsNullOrEmpty(input = Console.ReadLine())){ var charArray = input.ToCharArray(); var len = charArray.Length; for(int i = 0; i < len; i++){ if(char.IsLetter(charArray[i])){ str.Append(charArray[i]); }else{ str.Append(" "); } } string[] res = str.ToString().Split(" "); for(int i = res.Length-1; i >=0 ; i--){ Console.Write(res[i]+' '); } } } } }