2020牛客暑期多校训练营(第三场)B Classical String Problem
2020牛客暑期多校训练营(第三场)B Classical String Problem
题解:
这个题目还是有点难想的,你可以发现这个modify其实都可以转化成从前面找x个放到后面。
知道这个之后你就发现把这个字符串放到一个圈里,只是这个圈的起点在变化。
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
#define debug(x) printf("debug:%s=%d\n",#x,x);
//#define debug(x) cout << #x << ": " << x << endl
using namespace std;
const int maxn = 2e6+10;
typedef long long ll;
char s[maxn],a[10];
int main(){
scanf("%s",s);
int n = strlen(s),m,root=0;
scanf("%d",&m);
while(m--){
int x;
scanf("%s%d",a,&x);
if(a[0]=='A'){
x--;
printf("%c\n",s[(root+x)%n]);
}
else{
if(x<0) x+=n;
root=(root+x)%n;
}
}
return 0;
}