Advertisement
asdfg0998

dsaf

Oct 21st, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. string removeLeftOfStar(string s) {
  2.     string result = "";
  3.     for (char c : s) {
  4.         if (c == '*') {
  5.             if (!result.empty()) {
  6.                 result.pop_back();  // Remove the last character (left of *)
  7.             }
  8.         } else {
  9.             result += c;  // Append current character if not *
  10.         }
  11.     }
  12.     return result;
  13. }
  14.  
  15. int main() {
  16.     string s = "Magic*pin";
  17.     cout << "Original string: " << s << endl;
  18.     string modifiedString = removeLeftOfStar(s);
  19.     cout << "Modified string: " << modifiedString << endl;
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement