题解 | #单词倒排# | 正则即可
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String tmp = null;
while ((tmp=bf.readLine())!=null && !tmp.equals("")) {
String otherReg = "[^(a-z|A-Z|\\s)]";
tmp = tmp.replaceAll(otherReg, " ");
String[] strArr = tmp.split("\\s+");
for(int i=strArr.length-1;i>=0;i--){
System.out.print(strArr[i]+" ");
}
}
bf.close();
}
}
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String tmp = null;
while ((tmp=bf.readLine())!=null && !tmp.equals("")) {
String otherReg = "[^(a-z|A-Z|\\s)]";
tmp = tmp.replaceAll(otherReg, " ");
String[] strArr = tmp.split("\\s+");
for(int i=strArr.length-1;i>=0;i--){
System.out.print(strArr[i]+" ");
}
}
bf.close();
}
}