题解 | #单词倒排#
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
import java.util.; import java.io.;
public class Main{ public static void main(String[] args){
InputStreamReader reader = new InputStreamReader(System.in);
try(BufferedReader br = new BufferedReader(reader)){
String[] words = br.readLine().replaceAll("[^a-zA-Z]"," ").split(" ");
final StringBuffer sb = new StringBuffer();
for (int i = words.length - 1; i >= 0; i--) {
sb.append(words[i]);
if (i==0) continue;
sb.append(" ");
}
System.out.println(sb);
}catch (IOException e){
System.out.println(e.getMessage());
}
}
}