3AC 1TLE 6RE求助
查看原帖
3AC 1TLE 6RE求助
661913
liwenxi1145144444楼主2024/5/15 13:22
#include<bits/stdc++.h>
using namespace std;
string s;
int t;
int v1[1000005],v2[1000005]; 
int main(){
	ios::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	cin>>s>>t;
	int len=s.size();
	for(int i=0;i<len;i++){
		v1[i]=((i+1==len)?0:(i+1));
		v2[i]=((i-1==-1)?(len-1):(i-1));
	}
	int l=0,st=0;
	while(t--){
		char ch;
		cin>>ch;
		if(ch=='r'){
			if(l==0){
				st=v2[st];
			}else{
				st=v1[st];
			}
			l^=1;
			cin>>ch>>ch;
		}else if(ch=='>'){
			int x;
			cin>>x;
			if(l==0){
				st=(st-x+len)%len;
			}else{
				st=(st+x)%len;
			}
		}else{
			int x;
			cin>>x;
			if(l==0){
				st=(st+x)%len;
			}else{
				st=(st-x+len)%len;
			}
		}
	}
	if(l==0){
		int x=st;
		while(1){
			cout<<s[x];
			x=v1[x];
			if(x==st){
				break;
			}
		}
	}else{
		int x=st;
		while(1){
			cout<<s[x];
			x=v2[x];
			if(x==st){
				break;
			}
		}
	}
	return 0;
} 
2024/5/15 13:22
加载中...