#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { string s; getline(cin, s); reverse(s.begin(), s.end()); cout << s << endl; } // 64 位输出请用 printf("%lld")
- 字符串反转,就用字符串反转函数reverse()。
- reverse()要用,记得引入alg开头的头文件。
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { string s; getline(cin, s); reverse(s.begin(), s.end()); cout << s << endl; } // 64 位输出请用 printf("%lld")