社区讨论

2AC+8WA求条

P10058Reverse and Rotate参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mhz4gf5x
此快照首次捕获于
2025/11/15 01:18
4 个月前
此快照最后确认于
2025/11/16 13:57
4 个月前
查看原帖
rt,开long long了
CPP
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int rev=0;
    int x;
    int head=0;
    cin>>x;
    while(x--){
        string op;
        cin>>op;
        if(op==">"){
            int lef;
            cin>>lef;
            if(rev==0){
                head=(head-lef+s.length())%s.length();
            }else{
                head=(head+lef)%(s.length()-1);
            }
        }if(op=="<"){
            int lef;
            cin>>lef;
            if(rev==0)head=(head+lef)%(s.length()-1);
            else head=(head-lef+s.length())%s.length();
        }if(op=="rev"){
            rev^=1;
        }
    }
    if(rev==0)for(int i=head;i<s.length()+head;i++){
        cout<<s[i%s.length()];
    }
    else{
        for(int i=s.length()+head-1;i>=head;i--)
            cout<<s[i%s.length()];
    }
    return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...