Thinking of B-Classical String Problem (Niu Ke Duo School Third Session)

Insert picture description here
Insert picture description here
Idea: Directly treat this string as a loop. First define the starting position sx. For each operation, it is the sx = (sx+len1+x)%(len1);
problem to pay attention to that the data range is relatively large, and the time is stuck for me several times, and I use c++ The input and output of c must be remembered to close the input and output of 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;
}

Guess you like

Origin blog.csdn.net/qq_43811879/article/details/107866258