#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
getline(cin,str);
int pos1=0;
int pos2=int(str.length()-1);
for(int i=int(str.length()-1);i>=0;--i)
{
if(str[i]==' ')
{
pos1=i;
for(int j=pos1+1;j<=pos2;++j)
{
cout<<str[j];
}
cout<<str[pos1];
while(str[--pos1]==' ') ;
pos2=pos1;
i=pos1++;
}
if(i==0)
{
for(int j=i;j<=pos2;++j)
{
cout<<str[j];
}
}
}
return 0;
}
华为(5)单词倒排
最新推荐文章于 2023-04-06 03:45:00 发布
本文详细介绍了使用C++标准库中的iostream和string进行字符串读取、翻转和输出的操作方法,包括通过getline函数获取输入字符串,利用循环和条件判断实现字符串的翻转,并输出翻转后的字符串。
单词倒排&spm=1001.2101.3001.5002&articleId=37532985&d=1&t=3&u=93bb0b97694e46e9b84da1e9d6f5eb4b)
427

被折叠的 条评论
为什么被折叠?



