Skip to content
Author: lllyouo
Date: 20251020
tag: 队列
link: https://www.luogu.com.cn/problem/P11138

问题描述

link

分析

参考代码

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

struct Node {
    int x, y, z;
};

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int T; cin >> T;
    while (T--) {
        string s; cin >> s;

        queue<int> A, P, C;
        queue<Node> OP;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == 'A') A.push(i + 1);
            else if (s[i] == 'P' && P.size() < A.size()) P.push(i + 1);
            else if (s[i] == 'C' && C.size() < P.size()) {
                C.push(i + 1);

                s[A.front() - 1] = 'O';
                s[P.front() - 1] = 'O';
                s[C.front() - 1] = 'O';

                OP.push({A.front(), P.front(), C.front()});
                A.pop();
                P.pop();
                C.pop();
            }
        }

        bool flag = true;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] != 'O') {
                cout << s[i];
                flag = false;
            }
        }
        cout << endl;

        if (flag) cout << "Perfect" << endl;

        cout << OP.size() << endl;

        while (OP.size()) {
            cout << OP.front().x << " " << OP.front().y << " " << OP.front().z << endl;
            OP.pop();
        }
    }

    return 0;
}