题解 | #单词倒排#
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
判断是不是字母: Character.isLetter(ch[i])
import java.util.regex.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String test = sc.nextLine();
char[] ch = test.toCharArray();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < ch.length; i++) {
if (Character.isLetter(ch[i])) {
sb.append(ch[i]);
}else{
sb.append(" ");
}
}
String[] arr = sb.toString().split(" ");
for (int i = arr.length - 1; i >= 0; i--) {
System.out.print(arr[i]+" ");
}
}
}