网易9.5笔试 自动售货机
有大佬帮忙看看为啥不ac嘛 #笔试题目##网易#
自测可以过就是提交只过了百分之十
#include<iostream>
#include<stack>
#include<vector>
using namespace std;
int main(){
int n, m;
cin>>n>>m;
vector<stack<int> > st(n+1);
vector<int> value(n+1);
for(int i=1;i<=n;i++) cin>>value[i];
for(int k=0;k<m;k++){
int op_num;
cin>>op_num;
int left = -1, right=-1;
int cost = 0;
for(int i=0;i<op_num;i++){
string lr, op;
cin>>lr>>op;
if(op == "take"){
int index;
cin>>index;
if(!(st[index]).empty()){
int new_index = st[index].top();
st[index].pop();
index = new_index;
}
if(lr == "left"){
left = index;
}else{
right = index;
}
}else if(op == "keep"){
if(lr == "left"){
cost += value[left];
left = -1;
}else{
cost += value[right];
right = -1;
}
}else{
int index;
cin>>index;
if(lr == "left"){
if(left != index){
(st[index]).push(left);
}
left = -1;
}else{
if(right != index){
(st[index]).push(right);
}
right = -1;
}
}
}
if(left != -1) cost+=value[left];
if(right != -1) cost+=value[right];
cout<<cost<<endl;
}
}