2020牛客暑期多校训练营(第三场)B、Classical String Problem(模拟)

题目链接

题面:
在这里插入图片描述

题意:
给定字符串 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值