http://codeforces.com/contest/598/problem/B
http://www.chenguanghe.com/educational-codeforces-round-1-b-queries-on-a-string/
题目大意: 给一个string, 给l,r,k三个数, l和r是其中的char的index(以1为底), 求k次右shift后的string
分析: 没有什么算法, 就是注意是以1为底, 然后特殊情况有两种, 一个是k比r-l+1大, 所以取余, 另一个是r==l, 别的都是照常实现就好.
You are given a string s and should process m queries. Each query is described by two 1-based indices li, ri and integer ki. It means that you should cyclically shift the substring s[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 query l2 = 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 of s. 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 and ki (1 ≤ li ≤ ri ≤ |s|, 1 ≤ ki ≤ 1 000 000) — the description of the i-th query.
Output
Print the resulting string s after processing all m queries.
Examples
input
abacaba 2 3 6 1 1 4 2
output
baabcaa
题目大意: 给一个string, 给l,r,k三个数, l和r是其中的char的index(以1为底), 求k次右shift后的string
分析: 没有什么算法, 就是注意是以1为底, 然后特殊情况有两种, 一个是k比r-l+1大, 所以取余, 另一个是r==l, 别的都是照常实现就好.
public void solve(int testNumber, InputReader in, OutputWriter out) {
String s = in.readLine();
char[] chars = s.toCharArray();
int n = in.readInt();
for (int i = 0; i < n; i++) {
int l = in.readInt();
int r = in.readInt();
int k = in.readInt();
solve(chars,l-1,r-1,k);
}
out.print(chars);
}
private void solve(char[] ary, int l, int r, int k){
char[] tmp = new char[r-l+1];
k %= r-l+1;
for(int i = l; i <= r; i++){
tmp[(i-l+k)%(r-l+1)] = ary[i];
}
for(int i = l; i <= r; i++){
ary[i] = tmp[i-l];
}
}