blob: b3f8e4967ee610517949e191f225bce7fa2b5b72 (
plain) (
blame)
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
|
#include <iostream>
#include <stack>
#include <string>
std::string parse(const std::string& str) {
std::stack<char> result;
for (char ch : str) {
if (ch >= 'a' && ch <= 'z') {
result.push(ch);
} else if (ch == '*' && !result.empty()) {
result.pop();
} else if (ch == '$' && !result.empty()) {
result.push(result.top());
}
}
std::string finalResult;
while (!result.empty()) {
finalResult = result.top() + finalResult;
result.pop();
}
return finalResult;
}
int main() {
std::string input = "abc*$$*d$a$$zz*";
std::cout << "Result: " << parse(input) << std::endl;
return 0;
}
|