欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

牛客多校第三场 B【Classical String Problem】

程序员文章站 2022-04-02 18:51:38
...

牛客多校第三场 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;
    }
相关标签: 牛客多校