p166.ans1
======================
line lined line t
line c

=================
p166.cpp
======================
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

string commands;

void read() { getline(cin, commands); }

void solve() {
    // The hard part about this question is to understand what exactly the input
    // and output format is, otherwise it's just implementation.

    vector<string> lines = {""};
    int row = 0, col = 0;

    auto pad_line = [&](int r, int c) {
        if(c > (int)lines[r].size()) {
            lines[r].resize(c, ' ');
        }
    };

    for(int i = 0; i < (int)commands.size(); i++) {
        char c = commands[i];
        if(c == 'Q') {
            break;
        } else if(c >= 'a' && c <= 'z' || c == ' ') {
            pad_line(row, col);
            lines[row].insert(lines[row].begin() + col, c);
            col++;
        } else if(c == 'L') {
            if(col > 0) {
                col--;
            }
        } else if(c == 'R') {
            col++;
        } else if(c == 'U') {
            if(row > 0) {
                row--;
            }
        } else if(c == 'D') {
            if(row + 1 < (int)lines.size()) {
                row++;
            }
        } else if(c == 'N') {
            if(col > (int)lines[row].size()) {
                col = lines[row].size();
            }
            string tail = lines[row].substr(col);
            lines[row] = lines[row].substr(0, col);
            lines.insert(lines.begin() + row + 1, tail);
            row++;
            col = 0;
        } else if(c == 'E') {
            col = lines[row].size();
        } else if(c == 'H') {
            col = 0;
        } else if(c == 'X') {
            if(col < (int)lines[row].size()) {
                lines[row].erase(lines[row].begin() + col);
            } else if(row + 1 < (int)lines.size()) {
                pad_line(row, col);
                lines[row] += lines[row + 1];
                lines.erase(lines.begin() + row + 1);
            }
        } else if(c == 'B') {
            if(col > 0) {
                if(col <= (int)lines[row].size()) {
                    lines[row].erase(lines[row].begin() + col - 1);
                }
                col--;
            } else if(row > 0) {
                int prev_len = lines[row - 1].size();
                lines[row - 1] += lines[row];
                lines.erase(lines.begin() + row);
                row--;
                col = prev_len;
            }
        }
    }

    for(int i = 0; i < (int)lines.size(); i++) {
        if(i > 0) {
            cout << "\n";
        }
        cout << lines[i];
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        solve();
    }

    return 0;
}

=================
statement.txt
======================
166. Editor
time limit per test: 0.25 sec.
memory limit per test: 4096 KB
input: standard
output: standard



You are to write a simple text editor. This editor must supply next commands:

english lowercase letters or spaces: insert this letter in the current position of the cursor.
L: move cursor one position left. If current position in the beginning of the line, cursor mustn't move.
R: move cursor one position right. If the current position if after the end of the line, cursor must go beyond this end. If an english lowercase letter or space follows in command line, additional spaces must be added to the text.
U: move cursor a line up. If the current line is the first, cursor mustn't move.
D: move cursor a line down. If the current line is last, cursor mustn't move.
N: a new line must be added after the current. The part of the current line, which goes after the cursor position, must go on the new line. The cursor must go on the first position of the new line.
E: a cursor must move to a position after the end of the curent line.
H: a cursor must move to the first position of the current line.
X: current symbol must be deleted. The remaining part of the line must shift left. If the current position is after the end of the current line, additional spaces must be added to the current line and the next line must be attached to the current line; if the current position is after the end of the last line, nothing must happen.
B: the symbol before the the cursor must be deleted and the remaining part of the line must shift left. If the current position if after the end of the line, cursor must shift left one position. If the current symbol is the first of the line, then current line must be attached to the previous and remaining part must shift up; if the current symbol is the first symbol of the first line, nothing must happen.
Q: the editor must finish the work.


The editor starts from the blank file.

It is guaranted that in any moment while working length of each string does not exceed 1000 chars, and total number of commands does not exceed 20480.

Input
On the input there is the only line --- the list of commands of the editor.

Output
Write to the output the result of working of the editor. The EOLn (symbols with ASCII numbers 13 and 10) chars must be only between lines generated by editor (NOT after the last string!)

Sample test(s)

Input
lineRoUNLLLLline dDDDNline tline cLLLLLLNEUULLXRRRBXHBBHBBBBQsome left output

Output
line lined line t
line c
Author:	NNSU #2 team
Resource:	
Date:	







=================
p166.in1
======================
lineRoUNLLLLline dDDDNline tline cLLLLLLNEUULLXRRRBXHBBHBBBBQsome left output

=================
