字符串大类的题目还是使用java语言非常方便

public class Main{
        public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine();
        String [] str = s1.split(" ");
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = str.length-1; i >= 0 ; i--) {
            stringBuffer.append(str[i]+" ");
        }
        stringBuffer.deleteCharAt(stringBuffer.length()-1);
        System.out.println(stringBuffer.toString());
    }
}