Website Summary Files Commits Branches @commit @diff @stats
path: root / Seminar02 / task01.cpp
diff options
context:
space:
mode:
1 files changed, 20 insertions, 1 deletions
-rw-r--r--Seminar02/task01.cpp21
diff --git a/Seminar02/task01.cpp b/Seminar02/task01.cpp
index dfa97d7..288b3b5 100644
--- a/Seminar02/task01.cpp
+++ b/Seminar02/task01.cpp
@@ -27,6 +27,25 @@ std::string removeStars(const std::string& s) {
return res;
}
+std::string removeStarsTwo(const std::string& str) {
+ // As we are using only push_back and pop_back here
+ // the std::string is equivalent to a stack
+ // and we save up some time and memory.
+ std::string result;
+
+ for(char c : str) {
+ if(c == '*') {
+ result.pop_back();
+ }
+ else {
+ result.push_back(c);
+ }
+ }
+
+ return result;
+}
+
+
int main() {
-} \ No newline at end of file
+}