【中级】单词倒排

【中级】单词倒排

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

这道题如果会用正则匹配的话,完全配不上中级这个难度啊。
需要注意的就是把两头的空格去掉
代码如下:

import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String str = sc.nextLine().replaceAll("[^a-zA-Z]+", " ").trim();
            String[] words=str.split(" ");
            String result="";
            for(int i=words.length-1;i>=0;i--){
                result=result+words[i]+" ";
            }
            System.out.println(result.substring(0,result.length()-1));
        }

    }
}
全部评论

相关推荐

找到实习了 给了150一天 但是说是低代码 值得去吗
码农索隆:是在没实习,可去,待个一两周,不行就润呗
点赞 评论 收藏
分享
强大的马里奥:不太可能,我校计算机硕士就业率99%
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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