题解 | 单词倒排
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
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 str[] = sb.toString().split(" +");
for(int i = str.length-1;i>=0;i--){
System.out.print(str[i].trim()+" ");
}
}
}
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 str[] = sb.toString().split(" +");
for(int i = str.length-1;i>=0;i--){
System.out.print(str[i].trim()+" ");
}
}
}