题解 | #单词倒排#

单词倒排

http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836

import java.util.*;
public class Main {
    public Main(){
     
 }   
    public String reverse(String str){
        String[] words = str.split("[^A-Za-z]+");
        StringBuilder result = new StringBuilder();
        
        for(int i = words.length-1;i>=0;i--){
            result.append(words[i]).append(" ");
        }
        return result.toString().trim();
    }
    public static void main(String[] args){
        Main solution = new Main();
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
            String str = in.nextLine();
            String res = solution.reverse(str);
            System.out.println(res);
        }
    }
}
全部评论

相关推荐

白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
点赞 评论 收藏
分享
Twilight_mu:经典我朋友XXXX起手,这是那种经典的不知道目前行情搁那儿胡编乱造瞎指导的中年人,不用理这种**
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务