Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.5 kB
1
Indexable
Never
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define el '\n';

void solve() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    string s;
	int a=0, b=0, c=0, d=0, e=0, f=0;
    cin >> s;
    for (char x : s) {
        if (x == 'A')
            a++;
        else if (x == 'B')
            b++;
        else if (x == 'C')
            c++;
        else if (x == 'D')
            d++;
        else if (x == 'E')
            e++;
        else if (x == 'F')
            f++;
    }
    int min1 = min(a, d), min2 = min(e, b), min3 = min(c, f);
    a -= min1;
    d -= min1;
    c -= min3;
    f -= min3;
    b -= min2;
    e -= min2;

    while (!((a == 0 || d == 0) && (a == 0 || c == 0) && (b == 0 || e == 0) &&
           (c == 0 || f == 0) && (a == 0 || e == 0) && (b == 0 || d == 0) &&
           (b == 0 || f == 0) && (c == 0 || e == 0) && (d == 0 || f == 0))) {
        int min4 = min(a, c);
        a -= min4, c -= min4, b += min4;
        int min5 = min(a, e);
        a -= min5, e -= min5, f += min5;
        int min6 = min(b, d);
        b -= min6, d -= min6, c += min6;
        int min7 = min(b, f);
        b -= min7, f -= min7, a += min7;
        int min8 = min(c, e);
        e -= min8, c -= min8, d += min8;
        int min9 = min(c, a);
        c -= min9, a -= min9, b += min9;
        int min10 = min(d, f);
        d -= min10, f -= min10, e += min10;
    }
    cout << a + b + c + d + e + f << el;
}
signed main(){
	int t=(cin >>t,t);
	while(t--)solve();
}