解题思路:
reverse函数是最好用的,它还可以用在其他容器上,具体的可以再学习~
注意事项:
参考代码:
#include<bits/stdc++.h> using namespace std; /*方法一:通过reverse 函数*/ int main() { string str; while (cin >> str) { reverse(str.begin(), str.end()); cout << str << endl; } return 0; } /*方法二:直接通过string类的构造函数*/ /* int main() { string str; while (cin >> str) { string rev_str(str.rbegin(), str.rend()); cout << rev_str << endl; } return 0; } */ /*方法三:逐字符交换,需判断字符串长度的奇偶性*/ // ......
0.0分
0 人评分