Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string removeLeftOfStar(string s) {
- string result = "";
- for (char c : s) {
- if (c == '*') {
- if (!result.empty()) {
- result.pop_back(); // Remove the last character (left of *)
- }
- } else {
- result += c; // Append current character if not *
- }
- }
- return result;
- }
- int main() {
- string s = "Magic*pin";
- cout << "Original string: " << s << endl;
- string modifiedString = removeLeftOfStar(s);
- cout << "Modified string: " << modifiedString << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement