CF--B - Queries on a String


B. Queries on a String
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a string s and should processm queries. Each query is described by two 1-based indicesli,ri and integerki. It means that you should cyclically shift the substrings[li...ri]ki times. The queries should be processed one after another in the order they are given.

One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.

For example, if the string s is abacaba and the query is l1 = 3, r1 = 6, k1 = 1 then the answer is abbacaa. If after that we would process the queryl2 = 1, r2 = 4, k2 = 2 then we would get the string baabcaa.

Input

The first line of the input contains the string s (1 ≤ |s| ≤ 10 000) in its initial state, where|s| stands for the length ofs. It contains only lowercase English letters.

Second line contains a single integer m (1 ≤ m ≤ 300) — the number of queries.

The i-th of the next m lines contains three integers li,ri andki (1 ≤ li ≤ ri ≤ |s|, 1 ≤ ki ≤ 1 000 000) — the description of the i-th query.

Output

Print the resulting string s after processing allm queries.

Sample test(s)
Input
abacaba
2
3 6 1
1 4 2
Output
baabcaa
 
   
题意:给出一个字符串(1<=长度<=10000),再给出m进行m次查询,接下来m行,每一行三个数L,r,k,L--r表示将字符串这个区间内的字符当成一个环来逆时针转 k 次,得到一个新字符串,以后每次查询修改,都是在此字符串基础上进行的。
思路:先用一个字符串临时存放(L--r)的字符,因为下标是从0开始,所以是(src[L-1]到src[r-1])位字符,再按每次查询修改k次进行修改因是环,所以位置 i --> (i+k)%(r-L+1),再按其在临时串中位置与原串位置的对关系(tmp[0]--src[L-1]即tmp[i]--src[L-1+i])直接修改原串,这样方便些,不然直接在tmp串上修改不好操作。
 
   
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long ll;
using namespace std;
int main()
{
#ifdef OFFLINE
	freopen("t.txt","r", stdin);
#endif
	ll m, i, len, L, r, k;
	char src[11000], tmp[11000];
	scanf("%s", src);
	scanf("%lld", &m);
	while(m--){
		scanf("%lld %lld %lld", &L, &r, &k);
		len=0;
		for(i=L-1; i<=r-1;i++)
			tmp[len++] = src[i];//len刚好记录了tmp字符串长度
		for(i=0;i<len;i++){
			src[L-1+((i+k)%len)] = tmp[i];
		}
	}
	printf("%s\n", src);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值