注意:
PTA不支持gets(),所以我选择用cin.get()函数接收一行字符串
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdio.h>
using namespace std;
int main()
{
char str[85], ans[85][85];
cin.get(str, 90);
int len = strlen(str);
int row = 0, col = 0;
for (int i = 0; i < len; i++)
{
if (str[i] == ' ' || str[i] == '\n')
{
ans[row][col++] = '\0';
row++;
col = 0;
continue;
}
ans[row][col++] = str[i];
}
for (int i = row; i >= 0; i--)
{
if (i != 0)
{
printf("%s ", ans[i]);
}
else
{
printf("%s\n", ans[i]);
}
}
return 0;
}