Codeforces 598B Queries on a String(rotate(begin,mid,end))
2017-02-18 13:52
471 查看
B. Queries on a String
time limit per test 2 secondsmemory limit per test 256 megabytes
input standard input
output standard output
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.
Sample test(s)
input
abacaba
2
3 6 1
1 4 2
output
baabcaa
水题 循环移位
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; char a[10005]; int main(){ int n,l,r,k; scanf("%s",a); scanf("%d",&n); while(n--){ scanf("%d %d %d",&l,&r,&k); k=k%(r-l+1); rotate(a+l-1,a+r-k,a+r); } printf("%s",a); return 0; }
相关文章推荐
- vector<int>::iterator mid=(vi.begin()+vi.end())/2
- (转载)vector<int>::iterator mid=(vi.begin()+vi.end())/2
- 19、构建多线程应用程序:委托异步调用方法(BeginInvoke,EndInvoke,AsyncCallback)
- STL中vector容器 begin()与end()函数、front()与back()的用法
- BEGIN TRY...END TRY BEGIN CATCH... END CATCH 和错误级别
- 61. Rotate List(M);19. Remove Nth Node From End of List(M)
- iOS BUG: Unbalanced calls to begin/end appearance transitions for <XXXViewController: 0x7fcea3730650>.
- 对于begin和end的认识
- __BEGIN__; __END__是opencv中的一种错误处理机制,它可以防止非法的内存释放,以及内存泄露
- Unbalanced calls to begin/end appearance transitions for <IDOOrderHomeViewController: 0x8da2960>.
- mysql中的begin-end流程控制语句与局部变量
- STL中vector容器begin(),end(),push_back()等相关函数
- Ruby中用begin/end …rescue…ensure … raise 来处理异常
- BEGIN_MESSAGE_MAP 和END_MESSAGE_MAP() 这两个宏的具体实现与作用
- trim content between begin and end lines or get from keyword line to file end
- PAT (Advanced Level)1024. Palindromic Number (25) string的reverse() assign begin end rbegin rend
- C++中string类下的begin,end,rbegin,rend的用法
- vector之begin(),end(),front(),back()
- NS_ASSUME_NONNULL_BEGIN && NS_ASSUME_NONNULL_END
- 批量更新组件大小位置信息,BeginDeferWindowPos -- DeferWindowPos -- EndDeferWindowPos