输入:

I am a student

输出:

student a am I

最简单的做法:

#include <iostream>

using namespace std;

int main()
{
string str,res;
while(cin >> str) res=str+' '+res;
cout << res;
return 0;
}

做法2:

#include <iostream>

using namespace std;

int main()
{
string str[201];
int n=0;
while(cin >> str[n]) n++;
for(int i=n-1;i>=0;i--) cout << str[i] << ' ';
return 0;
}