-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackspace.cpp
More file actions
43 lines (36 loc) · 873 Bytes
/
backspace.cpp
File metadata and controls
43 lines (36 loc) · 873 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
#include <iostream>
using namespace std;
int main()
{
// Fast IO
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// Get the input string
string input;
cin >> input;
// Store the output string
string output;
// For each character in the input string
for(int i = 0; i < input.size(); i++)
{
// If it isn't a backspace
if(input[i] != '<')
{
// Add the character to the output
output.push_back(input[i]);
}
// If it's a backspace
else
{
// If there is a character that can be removed in the output
if(!output.empty())
{
// Remove that character
output.erase(--output.end());
}
}
}
// Print the output
cout << output << endl;
return 0;
}