NowCode:HJ12 字符串反转 发表于 2024-04-27 | 分类于 NowCode 题目: 字符串反转描述 接受一个只包含小写字母的字符串,然后输出该字符串反转后的字符串。(字符串长度不超过1000) 输入描述: 输入一行,为一个只包含小写字母的字符串。 输出描述: 输出该字符串反转后的字符串。 示例 12345输入:abcd输出:dcba 题解123456789101112131415#include <iostream>#include <algorithm>using namespace std;int main() { string input; getline(cin, input); auto first = input.begin(); auto last = input.end(); while(first != last && first != --last) { std::iter_swap(first, last); first++; } cout << input;} 思路与上一题基本一样,故不用一分钟就能做出来 此题简单