55. 右旋字符串(第八期模拟笔试)

题目

自己写的:

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    reverse(s.begin(), s.end());
    reverse(s.begin(), s.begin() + n);
    reverse(s.begin() + n, s.end());
    cout << s << endl;
    return 0;
}

整体反转和局部反转相结合,变变变,变出题目要求的样子。

卡哥思路差不多,不过讲的更详细。

posted @ 2025-01-15 23:12  hisun9  阅读(9)  评论(0)    收藏  举报