Website Summary Files Commits Branches @commit @diff @stats
path: root / Seminar02 / task01.cpp
diff options
context:
space:
mode:
Commitd8182cbb9e40f72ef96f40921b79a7add54ab0ce (patch)
Author
 Stoycho Kyosev <68247567+stoychoX@users.noreply.github.com>
2023-07-28 22:50:21 +0300
Committer
 GitHub <noreply@github.com>
2023-07-28 22:50:21 +0300
Files7b3a75a04f90dfc7282357aefe73b23325acf5e6 /Seminar02/task01.cpp
Data-structures-and-algorithms-d8182cbb9e40f72ef96f40921b79a7add54ab0ce.tar
Data-structures-and-algorithms-d8182cbb9e40f72ef96f40921b79a7add54ab0ce.tar.gz
Data-structures-and-algorithms-d8182cbb9e40f72ef96f40921b79a7add54ab0ce.zip
Parent8ab4cd05e3195432d7e1df5839424313db0348d9 (diff)
Update task01.cpp
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
+}