-
Notifications
You must be signed in to change notification settings - Fork 0
/
B. YetnotherrokenKeoard.cpp
86 lines (74 loc) · 1.5 KB
/
B. YetnotherrokenKeoard.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <string.h>
#include <cctype> // for tolower function
#include <cstring>//memset
#include <stack>
#define ll long long
#define Ragdha ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
void processKeyPresses(string& x, string& y)
{
stack<char> lowercaseStack, uppercaseStack;
for (int i = x.size() - 1; i > -1; i--)
{
if (x[i] == 'b')
{
lowercaseStack.push(x[i]);
}
else if (x[i] == 'B')
{
uppercaseStack.push(x[i]);
}
else
{
if (x[i] > 96)
{
// lowercase letter
if (!lowercaseStack.empty())
{
lowercaseStack.pop();
}
else
{
y += x[i];
}
}
else
{
// uppercase letter
if (!uppercaseStack.empty())
{
uppercaseStack.pop();
}
else
{
y += x[i];
}
}
}
}
reverse(y.begin(), y.end());
}
void solve()
{
string x, y;
cin >> x;
processKeyPresses(x, y);
cout << y << "\n";
}
int main()
{
Ragdha
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}