-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.cpp
More file actions
46 lines (33 loc) · 984 Bytes
/
editor.cpp
File metadata and controls
46 lines (33 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <vector>
using namespace std;
int main(void){
int i, length;
int cursor = 0;
string input;
string command_temp;
vector<char> command;
cin >> input >> length;
cin.get();
copy(input.begin(), input.end(), back_inserter(command));
cursor = command.size();
for(i = 0; i < length; i++){
getline(cin, command_temp);
if(command_temp.at(0) == 'L' && cursor != 0){
cursor -= 1;
}
if(command_temp.at(0) == 'D' && cursor != command.size()){
cursor += 1;
}
if(command_temp.at(0) == 'B' && cursor != 0){
command.erase(command.begin()+cursor-1);
cursor -= 1;
}
if(command_temp.at(0) == 'P'){
command.insert(command.begin()+cursor, command_temp.at(2));
cursor += 1;
}
}
cout << string(command.begin(), command.end()) << endl;
return 0;
}