AcWing 775. 倒排单词
原题链接
中等
作者:
蒟蒻--变革
,
2021-02-02 15:09:52
,
所有人可见
,
阅读 277
步骤
- 先将该字符串倒序存储
- 讲倒序存储的单词用字符流法逐个再次倒序输出
- 得到倒排单词
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
string a,b,str;
getline(cin, a);
for(int i = a.size() - 1; i >= 0; i--) b += a[i];
stringstream ssin(b);
while(ssin >> str)
{
for(int i = str.size() - 1; i >= 0; i--)
printf("%c",str[i]);
printf(" ");
}
}
acwing 江流儿解法
#include <iostream>
using namespace std;
int main()
{
string res,str;
while(cin >> str)
{
res = str + " "+ res ;
}
cout << res << endl;
}
yxc解法
#include <iostream>
using namespace std;
int main()
{
string str[100];
int i = 0;
while(cin >> str[i]) i++;
for(int k = i - 1; k >= 0; k--) cout << str[k] << " " ;
}