diff options
Update task01.cpp
1 files changed, 20 insertions, 1 deletions
| -rw-r--r-- | Seminar02/task01.cpp | 21 |
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 +} |
