题面:
题意:
给定字符串 S ,有两个操作:
(1)将字符串开头x个字符放到字符串尾部,或者将字符串尾部x字符放到字符串开头
(2)询问第 x 个字符是什么
题解:
我们可以把字符串首尾相接连接成一个环,然后维护一个开头位置。
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#define ui unsigned int
#define ll long long
#define llu unsigned ll
#define ld long double
#define pr make_pair
#define pb push_back
#define lc (cnt<<1)
#define rc (cnt<<1|1)
#define len(x) (t[(x)].r-t[(x)].l+1)
#define tmid ((l+r)>>1)
using namespace std;
const int inf=0x3f3f3f3f;
const ll lnf=0x3f3f3f3f3f3f3f3f;
const double dnf=1e18;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1.0);
const int hp=13331;
const int maxn=2000100;
const int maxm=100100;
const int up=100000;
char str[maxn];
char op[10];
int main(void)
{
scanf("%s",str);
int len=strlen(str);
int s=0;
int q,x;
scanf("%d",&q);
while(q--)
{
scanf("%s%d",op,&x);
if(op[0]=='M')
{
s=(s+x+len)%len;
}
else
{
printf("%c\n",str[(s+x-1+len)%len]);
}
}
return 0;
}