题解 | #单词倒排#

单词倒排

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static java.util.stream.Stream.*;


public class Main {
    public static void main(String[] args) throws IOException {

        //testCompletePack();
        testTh();
    }

    private static void testTh() throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String str;
        StringBuilder sb = new StringBuilder();
        while ((str = bf.readLine()) != null) {
            char[] chars = str.toCharArray();
            for (int i = 0; i < chars.length; i++) {
                if ((chars[i] >= 'a' && chars[i] <= 'z') || (chars[i] >= 'A' &&
                        chars[i] <= 'Z')) {
                    continue;
                } else {
                    String temp = chars[i] + "";
                    str = str.replace(temp, " ");
                }
            }
            String[] split = str.split(" ");
            for (int i = split.length - 1; i >= 0; i--) {
                System.out.print(split[i] + " ");
            }

        }
    }

}

全部评论

相关推荐

09-08 17:17
同济大学 Java
狗不理fe:里面的人劝一句,别来虾,我们部门24校招生淘汰率30%,还有一些人说有一年保护期,不可能!!!
我的秋招日记
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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