118 翻转字符串(2)- 块移动
Table of Contents

ac

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);

    public static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws Exception {
        String sizeStr = reader.readLine();
        int size = Integer.valueOf(sizeStr);
        String s = reader.readLine();
        int len = s.length();
        char[] chars = s.toCharArray();

        // 两部分翻转
        revers(chars, 0, size-1);
        revers(chars, size, len-1);

        // 整体翻转
        revers(chars, 0, len-1);

        // print
        System.out.println(chars);
    }

    static void revers(char[] chars, int l, int r) {
        char temp;
        while(l < r) {
            temp = chars[l];
            chars[l] = chars[r];
            chars[r] = temp;
            l++;
            r--;
        }
    }

}
/*
3
abcdefg

defgabc

// 1.
cba gfed
// 2.
defgabc

*/