题解 | #单词倒排#
单词倒排
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] + " "); } } }