首页 > 其他分享 >倒排单词

倒排单词

时间:2022-11-27 22:42:48浏览次数:43  
标签:cout 倒排 int res am 单词 str namespace

输入:

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;
}

标签:cout,倒排,int,res,am,单词,str,namespace
From: https://blog.51cto.com/u_15815053/5890409

相关文章