题解 | #单词倒排#倒着验证,非字母跳过,字母截取
单词倒排
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 s=sc.nextLine();
int n=s.length();
int i=n-1;
int j=n-1;
StringBuilder sb=new StringBuilder();
while(j>=0){
while(j>=0 && !Character.isLetter(s.charAt(j))){
j--;
}
i=j;
while(j>=0 && Character.isLetter(s.charAt(j))){
j--;
}
sb.append(s.substring(j+1,i+1)+" ");
}
sb.deleteCharAt(sb.length()-1);
System.out.println(sb.toString());
}
}