Website Summary Files Commits Branches @commit @diff @stats
path: root / Seminar02 / task01.cpp
blob: dfa97d78fc833f2a38c4eb19b761e6f03bfdd9a2 (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<string>
#include<stack>
#include<iostream>

std::string removeStars(const std::string& s) {
	std::stack<char> st;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '*') {
			if (st.empty())
				throw "invalid expr";
			else
				st.pop();
		}
		else
			st.push(s[i]);
	}

	std::string res(st.size(), '\0');
	size_t idx = st.size() - 1;

	while (!st.empty()) {
		res[idx--] = st.top();
		st.pop();
	}

	return res;
}

int main() {

}