思路:直接把这个字符串当做环来看,先定义起始位置sx,每次操作也就是sx = (sx+len1+x)%(len1);
这道题要注意的就是数据范围给的比较大,卡时间卡了我好几次,用的是c++的输入输出,一定要记住关闭c的输入输出。ios::sync_with_stdio(false);
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
string s; cin>>s;
int len1 = s.length();
int q; cin>>q;int sx = 0;
while(q--){
char c; int x;
cin>>c>>x;
if(c=='M'){
//修改操作
sx = (sx+len1+x)%(len1);
}
else {
cout<<s[(sx+x-1)%len1]<<endl;
}
}
return 0;
}