ITGUY15 - Editorial

Problem: https://www.codechef.com/PBK12020/problems/ITGUY15

DIFFICULTY:

EASY.

PROBLEM:

The chef is having one string of English lower case alphabets only. The chef wants to remove all “abc” special pairs where a,b,c are occurring consecutively. After removing the pair, create a new string and again remove “abc” special pair from a newly formed string. Repeate the process until no such pair remains in a string.

Program:

#include <bits/stdc++.h> // Include every standard library
using namespace std;
#define ll long long;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;

        for (size_t i = 0; i + 2 < s.length(); i++) {
            if (s[i] == 'a' && s[i + 1] == 'b'
                && s[i + 2] == 'c') {
                s.erase(i, 3);
                i = -1;
            }
        }
        cout << s << endl;
    }
    return 0;

}

1 Like