题解 | #单词倒排#

单词倒排

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

import java.util.*;
 
public class Main {
     public static void main(String[] args) {
         Scanner in = new Scanner(System.in);
          String str = in.nextLine();
         LinkedList<String> list=new LinkedList<>();
         String str1="";
         for(char ch: str.toCharArray()){
             if(ch<='z'&&ch>='a'||ch>='A'&&ch<='Z'){
                 str1+=ch;
             }
             else{
                 if(str1!=""){
                      list.add(str1);
                 }
                 str1="";
             }
         }
          if(str1!=""){
                      list.add(str1);
                 }
             String strans="";
             for(int i=list.size()-1;i>0;i--){
                  strans+=list.pollLast()+" ";
             }
              strans+=list.pollLast();
             System.out.println(strans);
             
             
         
     }
}
使用队列,简单易懂

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 13:47
机械打工仔:你自己匿名可以,这么好的公司就别给它匿名了
点赞 评论 收藏
分享
求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
07-01 23:23
郑州大学 Java
否极泰来来来来:牛客迟早有高三的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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