From d8182cbb9e40f72ef96f40921b79a7add54ab0ce Mon Sep 17 00:00:00 2001 From: Stoycho Kyosev <68247567+stoychoX@users.noreply.github.com> Date: Fri, 28 Jul 2023 22:50:21 +0300 Subject: Update task01.cpp --- Seminar02/task01.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'Seminar02/task01.cpp') 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 +} -- cgit v1.3.1-23-gd82d