题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String line = sc.nextLine(); char[] ch = line.toCharArray(); for(int i=0;i<ch.length;i++){ if((ch[i]>='a'&& ch[i]<='z')||(ch[i]>='A'&&ch[i]<='Z')){ continue; }else{ ch[i]=' '; } } String[] str = String.valueOf(ch).split(" "); for(int i=str.length-1;i>=0;i--){ System.out.print(str[i]+" "); } } }