题解 | #单词倒排#
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
replaceAll() https://www.runoob.com/java/java-string-replaceall.html
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()){
// String[] str = sc.nextLine().split("[^A-Za-z]+");
String str = sc.nextLine();
String replaceStr = str.replaceAll("[^A-Za-z]+", " ");
String[] strArr = replaceStr.split(" ");
// StringBuilder sb = new StringBuilder();
for (int i = strArr.length - 1; i >= 0; i--) {
System.out.print(strArr[i] + " ");
}
}
}
}