解法一
✅ 完整代碼
評分結果(參考) : AC (48ms, 352KB)
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int stk1_size=0, stk2_size=0;
string op;
while(cin >> op){
if(op == "push"){
cin.ignore(999, '\n');
stk1_size++;
cout << 1;
}
else{
if(stk2_size > 0){
stk2_size--;
cout << 4;
continue;
}
stk2_size += stk1_size;
while(stk1_size > 0){ cout << 5; stk1_size--; }
stk2_size--;
cout << 4;
}
}
return 0;
}