题目描述:
输入描述:
输出描述:
示例
输入:
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;
}