P10058 题解
FurippuWRY · · 题解
可以将
定义变量
若最终的
至于为什么
可以用双端队列模拟,感觉会比纯数组方便的多。
#include<bits/stdc++.h>
#define int long long
using namespace std;
deque<char> n;
int t, x, len, cnt = 0, p = 0;
string opt, s;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> s;
len = s.size();
for (int i = 0; i < len; ++i) n.push_back(s[i]);
cin >> t;
while (t--) {
cin >> opt;
if (opt[0] == '<') {
cin >> x;
cnt -= x;
}
else if (opt[0] == '>') {
cin >> x;
cnt += x;
}
else {
p++;
cnt = -cnt;
}
}
if (p & 1) reverse(n.begin(), n.end());
if (cnt > 0) {
for (int i = 1; i <= cnt % len; ++i) {
n.push_front(n.back());
n.pop_back();
}
}
else if (cnt < 0) {
for (int i = 1; i <= -cnt % len; ++i) {
n.push_back(n.front());
n.pop_front();
}
}
for (auto i : n) cout << i;
return 0;
}