#include<stdio.h>
int main(){
char a[80][80];//定义二维数组存储每个字符串
int i=1;
scanf("%s",a[0]);//先把第一个单词读进来
//scanf自动遇到空格停止,因此这个scanf只会读取第一个,然后紧接着用getchar()获取下一个空格字符
char ch=getchar();//把第一个空格读进来
while(ch!='\n'){//一直循环读取单词-空格-单词-空格....直到读取到回车为止
scanf("%s",a[i++]);//存储每个单词
ch=getchar();
}
//打印输出
for(int j=i-1;j>=0;j--){
printf("%s",a[j]);
if(j!=0)printf(" ");
}
return 0;
}
就是用中间的空格把字符串分开存到数组中,倒着输出即可