Creative Candy Consumption

Problem Link

Solution by TioPatinhas100 pts

Code / Notes

#include <bits/stdc++.h>
using namespace std;

// Problema Atual: 3
int main() {
	string a, b;
    cin >> a >> b;
    queue<char>Q;
    queue<char>P;
    for (auto c : a) Q.push(c);
    for (auto c : b) P.push(c);
    int cnt = 0;
    int cnt2 = 0;
    while (!P.empty() and !Q.empty()) { 
        char c = Q.front();
        char d = P.front();
        if (c == 'R' && d == 'G') {
            cnt++;
            P.pop();
        }
        else if (c == 'G' && d == 'B') {
            cnt++;
            P.pop();
        }
        else if (c == 'B' && d == 'R') {
            cnt++;
            P.pop();
        }
        else if (c == d) {
            cnt++;
            cnt2++;
            P.pop();
            Q.pop();
        }
        else {
            cnt2++;
            Q.pop();
        }
    }
    if (Q.empty()) {
        cnt2 += P.size();
    }
    if (P.empty()) {
        cnt += Q.size();
    }
    cout << cnt << endl;
    cout << cnt2 << endl;
}

Last updated 15 hours, 30 minutes ago


« Back to problem