about summary refs log tree commit diff
path: root/others/easy20160714/16.c
blob: 33334cd3d1988b13e3ca6f82194b80e657e501fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>

int main()
{
	FILE *fi = fopen("INP.TXT", "r"), *fo = fopen("OUT.TXT", "w");
	unsigned char n, i, j, s[256], sx[256], x, y;

	fscanf(fi, "%s %hhd\n", s, &n);

	for (i = 0; i < n; i++)
		if (fgetc(fi) ^ 49) {
			fscanf(fi, " %hhd %hhd\n", &x, &y);
			x--;
			memmove(s + x, s + x + y, strlen(s) - x - y + 1);
			fprintf(fo, "%s\n", s);
		} else {
			fscanf(fi, " %s %hhd\n", sx, &y);
			strcpy(sx + strlen(sx), s + y);
			strcpy(s + y, sx);
			fprintf(fo, "%s\n", s);
		}

	fcloseall();

	return 0;
}