题解 | #单词倒排#

单词倒排

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

import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String oriStr = br.readLine();
        StringBuilder converted = new StringBuilder();
        for(int i = 0; i < oriStr.length(); i++){
            char c = oriStr.charAt(i);
            if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')){
                converted.append(c);
            }else{
                converted.append(" ");
            }
        }
        String[] strings = converted.toString().split(" ");
        for(int i = strings.length - 1; i >= 0; i--){
            System.out.print(strings[i] + " ");
        }       
    }
}
全部评论

相关推荐

点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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