CodeForces
来源:互联网 发布:淘宝退货流程图 编辑:程序博客网 时间:2024/06/10 03:36
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 isabbacaa. If after that we would process the queryl2 = 1, r2 = 4, k2 = 2 then we would get the stringbaabcaa.
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 andki (1 ≤ li ≤ ri ≤ |s|, 1 ≤ ki ≤ 1 000 000) — the description of the i-th query.
Print the resulting string s after processing allm queries.
abacaba23 6 11 4 2
baabcaa
虽然说是水题,但我看题看了好久才看懂。。。
题目大意就是给你个字符串,执行若干次操作后输出该字符串
每次操作就是将给定区间[l,r]的所有字母首尾相连形成一个环,然后环上每个元素向后移动k位(其实就是循环移动,只是我不会表述)
代码
#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<cmath>using namespace std;int pos[10005];//用该数组保存该位置对应字母在char[]数组中的位置int prepos[10005];//用该数组保存该位置之前对应字母在char[]数组中的位置char t[10005];int main(){ int m,l,r,k; while(cin>>t) { int n=strlen(t); for(int i = 1; i <= n; i++) { pos[i]=i; prepos[i]=i; } cin>>m; for(int i = 0; i < m; i++) { cin>>l>>r>>k; for(int j = r; j >= l; j--) { int temp=l+(j-l+k)%(r-l+1); pos[temp] = prepos[j]; } for(int j = r; j >= l; j--) prepos[j]=pos[j]; } for(int i =1; i <= n; i++) cout<<t[pos[i]-1]; cout<<endl; } return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 如何将exe文件包装为Windows服务
- 浏览器的加载、解析、和渲染--总结
- JAVA学习60_Java从字符串中提取数字
- eclipse+tomcat+jdk安装配置
- POJ 1001 Exponentiation(高精度乘法)
- CodeForces
- Unicode以及.rc的一点问题
- 天机测试单板(Tianjic2)调试总结
- 配置Redhat 7 使用CentOS的YUM源
- SpringMVC核心~~持续更新~
- <a>标签跳外部链接
- 关于windows下,PHP创建目录、文档名时中文乱码问题
- Java中的Comparable与Comparator
- 乐观锁和悲观锁的区别(最全面的分析)