题解 | #字符串反转#
字符串反转
http://www.nowcoder.com/practice/e45e078701ab4e4cb49393ae30f1bb04
读入字符串str,从后向前遍历str拼装成一个新的字符串ret传出,最后输出新的字符串
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string fun(string str)
{
string ret;
for(auto iter=str.rbegin(); iter!=str.rend(); iter++)
{
ret += *iter;
}
return ret;
}
int main()
{
string str;
while(cin >> str)
cout << fun(str);
return 0;
}
360集团公司福利 401人发布