牛客多校第三场 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;
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值