ohwhatalovelyday

Untitled

Feb 9th, 2024
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define FASTER() ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  4. #define ff first
  5. #define ss second
  6. #define pb push_back
  7. #define all(a) a.begin(), a.end()
  8. #define dbg(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
  9.  
  10. typedef long long ll;
  11.  
  12. using namespace std;
  13.  
  14. void print(vector <string> &v) {
  15.     cout << "printing: \n";
  16.     for(auto a : v) {
  17.         cout << "1 " << a << '\n';
  18.     }
  19. }
  20.  
  21. void solve() {
  22.     string s;
  23.     cin >> s;
  24.     vector <string> ans;
  25.     ans.push_back("");
  26.     int cur_col = 0;
  27.     int cur_row = 0;
  28.     for(auto c: s) {
  29.         if(c == 'L') {
  30.             cur_col = max(cur_col - 1, 0);
  31.         } else if(c == 'R') {
  32.             cur_col = min(cur_col + 1, (int)ans[cur_row].size()); // в конец
  33.         } else if(c == 'U') {
  34.             cur_row = max(cur_row - 1, 0);
  35.             cur_col = min(cur_col, (int)ans[cur_row].size());
  36.         } else if(c == 'D') {
  37.             cur_row = min(cur_row, (int)ans.size() - 1);
  38.             cur_col = min(cur_col, (int)ans[cur_row].size()); // встаем в конец
  39.         } else if(c == 'B') {
  40.             cur_col = 0;
  41.         } else if(c == 'E') {
  42.             cur_col = (int)ans[cur_row].size(); // в конец
  43.         } else if(c == 'N') {
  44.             string cur_str = ans[cur_row];
  45.             string fi = cur_str.substr(0, cur_col);
  46.             string se = cur_str.substr(cur_col, (int)cur_str.size() - cur_col);
  47.             ans[cur_row] = fi;
  48.             ans.insert(ans.begin()+cur_row + 1, se);
  49.             cur_row++;
  50.             cur_col = 0;
  51.         } else {
  52. //            dbg(c);
  53.             ans[cur_row].insert(cur_col, 1, c);
  54.             cur_col++;
  55. //            dbg(ans[cur_row]);
  56.         }
  57.     }
  58.     for(auto a : ans) {
  59.         cout << a << '\n';
  60.     }
  61.     cout << '-' << '\n';
  62. }
  63.  
  64. int main() {
  65.     FASTER();
  66.     int t;
  67.     cin >> t;
  68.     while(t--) {
  69.         solve();
  70.     }
  71. }
  72.  
  73. //1
  74. //abNcdULNg
Advertisement
Add Comment
Please, Sign In to add comment