2020牛客暑期多校训练营(第三场)------ Classical String Problem

题目描述:

在这里插入图片描述

输入描述:

在这里插入图片描述

输出描述:

在这里插入图片描述

示例

输入:
nowcoder
6
A 1
M 4
A 6
M -3
M 1
A 1
输出:
n
o
w

备注:

Initially, S is ‘nowcoder’, six operations follow.

• The 1-st operation is asking what the 1-st letter is. The answer is 'n'.
• The 2-nd operation is to move the leftmost 4 letters to the rightmost side, so S is modified to 'odernowc'.
• The 3-rd operation is asking what the 6-th letter is. The answer is 'o'.
• The 4-th operation is to move the rightmost 3 letters to the leftmost side, so S is modified to 'owcodern'.
• The 5-th operation is to move the leftmost 1 letter to the rightmost side, so S is modified to 'wcoderno'.
• The 6-th operation is asking what the 1-st letter is. The answer is 'w'.

String函数substr()的简单运用

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s;
    char c;
    ll int T,x;
    cin>>s>>T;
    ll int len=s.size();
    while(T--){
        cin>>c>>x;
        if(c=='M'){
            if(x>0){
                s=s.substr(x,len)+s.substr(0,x);
            }
            else{
                x=abs(x);
                s=s.substr(len-x)+s.substr(0,len-x);
            }
        }
        else
            cout<<s[x-1]<<endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值