2021-PTA总决赛-L2-1 包装机(队列+栈,纯模拟)

题目怎么说就怎么做

AcCode:

#include<bits/stdc++.h>
using namespace std;
queue<char> track[110];
stack<char> s;
int main(){
    int N, M, S;
    cin >> N >> M >> S;
    for(int x = 1; x <= N; x++){
        for(int i = 0; i < M; i++){
            char ch;
            cin >> ch;
            track[x].push(ch);
        }
    }
    while(true){
        int operate;
        cin >> operate;
        if(operate == -1) break;
        if(operate == 0 && !s.empty()){
            cout << s.top();
            s.pop();
        }else{
            if(!track[operate].empty()){
                if(s.size() == S){
                    cout << s.top();
                    s.pop();
                    s.push(track[operate].front());
                    track[operate].pop();
                }else{
                    s.push(track[operate].front());
                    track[operate].pop();
                }
            }
        }
    }
    return 0;
}
posted @ 2025-03-15 01:06  Yuhhhhh  阅读(20)  评论(0)    收藏  举报