Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define FASTER() ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
- #define ff first
- #define ss second
- #define pb push_back
- #define all(a) a.begin(), a.end()
- #define dbg(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
- typedef long long ll;
- using namespace std;
- void print(vector <string> &v) {
- cout << "printing: \n";
- for(auto a : v) {
- cout << "1 " << a << '\n';
- }
- }
- void solve() {
- string s;
- cin >> s;
- vector <string> ans;
- ans.push_back("");
- int cur_col = 0;
- int cur_row = 0;
- for(auto c: s) {
- if(c == 'L') {
- cur_col = max(cur_col - 1, 0);
- } else if(c == 'R') {
- cur_col = min(cur_col + 1, (int)ans[cur_row].size()); // в конец
- } else if(c == 'U') {
- cur_row = max(cur_row - 1, 0);
- cur_col = min(cur_col, (int)ans[cur_row].size());
- } else if(c == 'D') {
- cur_row = min(cur_row, (int)ans.size() - 1);
- cur_col = min(cur_col, (int)ans[cur_row].size()); // встаем в конец
- } else if(c == 'B') {
- cur_col = 0;
- } else if(c == 'E') {
- cur_col = (int)ans[cur_row].size(); // в конец
- } else if(c == 'N') {
- string cur_str = ans[cur_row];
- string fi = cur_str.substr(0, cur_col);
- string se = cur_str.substr(cur_col, (int)cur_str.size() - cur_col);
- ans[cur_row] = fi;
- ans.insert(ans.begin()+cur_row + 1, se);
- cur_row++;
- cur_col = 0;
- } else {
- // dbg(c);
- ans[cur_row].insert(cur_col, 1, c);
- cur_col++;
- // dbg(ans[cur_row]);
- }
- }
- for(auto a : ans) {
- cout << a << '\n';
- }
- cout << '-' << '\n';
- }
- int main() {
- FASTER();
- int t;
- cin >> t;
- while(t--) {
- solve();
- }
- }
- //1
- //abNcdULNg
Advertisement
Add Comment
Please, Sign In to add comment