牛客多校第三场 B【Classical String Problem】
牛客多校第三场 B【Classical String Problem】
链接:https://ac.nowcoder.com/acm/contest/5668/B
来源:牛客网
题目描述
Given a string S consists of lower case letters. You’re going to perform Q operations one by one. Each operation can be one of the following two types:
Modify: Given an integer x. You need to modify S according to the value of x. If x is positive, move the leftmost x letters in S to the right side of S; otherwise, move the rightmost |x| letters in S to the left side of S.
Answer: Given a positive integer x. Please answer what the x-th letter in the current string S is.
输入描述:
There are Q+2 lines in the input. The first line of the input contains the string S. The second line contains the integer Q. The following Q lines each denotes an operation. You need to follow the order in the input when performing those operations.
Each operation in the input is represented by a character c and an integer x. If c = ‘M’, this operation is a modify operation, that is, to rearrange S according to the value of x; if c = ‘A’, this operation is an answer operation, to answer what the x-th letter in the current string S is.
• 2 \le |S| \le 2 \times 10^62≤∣S∣≤2×10
6
(|S| stands for the length of the string S)
• S consists of lower case letters
• 1 \le Q \le 8 \times 10^51≤Q≤8×10
5
• c = 'M' or 'A'
• If c = 'M', 1 \le |x| < |S|1≤∣x∣<∣S∣
• If c = 'A', 1 \le x \le |S|1≤x≤∣S∣
• There is at least one operation in the input satisfies c = 'A'
输出描述:
For each answer operation, please output a letter in a separate line representing the answer to the operation. The order of the output should match the order of the operations in the input.
示例1
输入
nowcoder
6
A 1
M 4
A 6
M -3
M 1
A 1
输出
n
o
w
找规律!!!暴力ttt
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
using namespace std;
typedef long long ll;
string a;
int main()
{
ll len;
ll k;
char c;
ll b,x=0,m=0;
cin>>a;
scanf("%lld",&k);
len=a.size();
for(int i=0;i<2*k;i++)
{
scanf("%c %lld",&c,&b);
if(c=='M')
{
x=m+b;
if(x<0)
x+=len;
m=x%len;
}
//cout<<m;
ll n;
if(c=='A')
{
n=(m+b-1)%len;
printf("%c\n",a[n]);
}
}
return 0;
}
上一篇: unity使用Netjson自定义向量Vector解析
下一篇: 框架的问题
推荐阅读
-
牛客多校第三场 A-Clam and Fish【贪心】+ B-Classical String Problem【思维】
-
2020牛客多校第三场-J Just Shuffle
-
2020牛客多校第三场 E Two Matchings
-
2020牛客暑期多校 第一场 F Infinite String Comparision(字符串)
-
2020牛客暑期多校 第二场 B Boundary(计算几何)
-
2020牛客多校第三场 F-Fraction Construction Problem
-
牛客(多校4):Basic Gcd Problem
-
2020牛客多校第3场:[Points Construction Problem + 思维题+构造]
-
2020牛客多校(第一场) F- Infinite String Comparision
-
[扩展欧拉函数] 牛客2020多校第三场 F.Fraction Construction Problem