题解 | #字符逆序#
字符逆序
https://www.nowcoder.com/practice/cc57022cb4194697ac30bcb566aeb47b
#include <iostream>
#include<string>
#include<vector>
using namespace std;
/* 将一个字符串str的内容颠倒过来,并输出。
数据范围:
1≤len(str)≤10000
输入描述:
输入一个字符串,可以有空格
输出描述:
输出逆序的字符串*/
int main()
{
// 输入可以有空格 可以采用getline()
string str;
getline(cin, str);
for (auto it = str.rbegin(); it != str.rend(); it++)//采用逆序迭代器
{
cout << *it ;
}
system("pause");
return 0;
}

查看50道真题和解析