题解 | #单词倒排#

单词倒排

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]+' ');
                }
                
            }
        }
    }
}


全部评论

相关推荐

认真搞学习:这个真喷不了,你是我见过最美的牛客女孩
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务