一.相关链接
题目链接:右旋字符串
二.心得体会
这道题是一道字符串题目,思路其实很简单。和151.翻转字符串里的单词相似,我们只需要将字符串分为两个单词,然后分别进行翻转操作就行了。
首先将整个字符串翻转,然后依次翻转两个子字符串就行。
三.代码
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int num;
string s;
while(cin>>num){
cin>>s;
reverse(s.begin(),s.end());
reverse(s.begin(),s.begin()+num);
reverse(s.begin()+num,s.end());
cout<<s;
}
}