题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ String s = scanner.nextLine(); // System.out.println(s); String[] split = s.split("[^a-zA-Z]+"); if (split[0].equals("")){ String[] scp = new String[split.length - 1]; System.arraycopy(split,1,scp,0,split.length-1); split=scp; } // System.out.println(Arrays.toString(split)); // System.out.println(split.length); String ss=""; for (int i = split.length-1; i >=0; i--) { split[i]=split[i]+" "; ss=ss+split[i]; } System.out.println(ss); // System.out.println(Arrays.toString(split)); } } }