#include "string"
#include "stdio.h"
#include "iostream"
using namespace std;
void myreverse(string &str,int left,int right)
{
while(left<right)
{
char temp=str[left];
str[left]=str[right];
str[right]=temp;
left++;
right--;
}
}
void rotateString(string &str,int offset)
{
if(str.size()==0)
return;
int len=str.size();
offset%=len;
myreverse(str,0,len-offset-1);
myreverse(str,len-offset,len-1);
myreverse(str,0,len-1);
}
int main()
{
string str;
int offset;
cin>>str;
cin>>offset;
rotateString(str,offset);
return 0;
}
字符串反转
最新推荐文章于 2022-02-27 09:09:15 发布