package jiegouSuanfa;
import java.util.Scanner;
/**
* 在原字符串中把字符串尾部的m个字符移动到字符串的头部,要求:长度为n的字符串操作时间复杂度为O(n),空间复杂度为O(1)。
* 例如,原字符串为”Ilovebaofeng”,m=7,输出结果为:”baofengIlove”
* @author 97699
*
*/
public class StringReserve {
private static String str="IloveCY";
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int k=sc.nextInt();
k=k%str.length();
k=str.length()-k;
char[] m=str.toCharArray();
int len=m.length;
reverse(m,0,k-1);//将字符串进行翻转
reverse(m,k,len-1);
reverse(m,0,len-1);
System.out.println(m);
}
private static void reverse(char[] m, int k, int i) {
// TODO Auto-generated method stub
while(k<i) {
char t=m[k];
m[k]=m[i];
m[i]=t;
k++;
i--;
}
}
}