#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { int n, q; while (scanf("%d %d", &n, &q) != EOF) { char *str = (char*)malloc(sizeof(char) * (n + 1)); if(str == NULL) { printf("内存分配失败"); return 0; } scanf("%s",str); str[n] = '\0'; int l, r; for(int i = 0; i < q; i++) { scanf("%d %d", &l, &r); int len = strlen(str); char* tmp = (char*)malloc(sizeof(char) * (len + r - l + 1)); for(int j = 0; j < l - 1; j++) { tmp[j] = str[j]; } int index = l - 1; for(int j = l - 1; j < r; j++) { tmp[index] = str[j]; index++; tmp[index] = str[j]; index++; } for(int j = r; j < len; j++) { tmp[index] = str[j]; index++; } tmp[index] = '\0'; str = tmp; } printf("%s\n",str); } return 0; }