分治法——循环左移

// test.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include <type_traits>
using namespace std;

void reverse(char a[], int low, int high) {
    int i = low, j = high, temp;
    while (i < j) {
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;
        i++;
        j--;
    }
}

void move(char a[], int n, int p) {
    reverse(a, 0, p - 1);
    reverse(a, p, n - 1);
    reverse(a, 0, n - 1);
}

int main()
{
    int length, p;
    char a[100];
    cin >> length;
    cin >> p;
    cin >> a;
    
    move(a, length, p);
    cout << a;
        return 0;
}

猜你喜欢

转载自www.cnblogs.com/ZengWeiHao/p/10451826.html