malloc_88 2020-04-24 17:19 采纳率: 0%
浏览 112

PAT A1057 STACK(30) 有没有大佬能帮我看看这道题哪里错了?只得了10分

图片说明

图片说明
图片说明

#include<cstdio>
#include<string>
#include<iostream>
#include<stack>
#include<set>
using namespace std;
int n;
int main()
{
    cin>>n;
    stack<int> s;
    multiset<int> order;
    int key;
    for(int i = 0; i < n; i++)
    {
        string ope;
        cin>>ope;
        if(ope == "Push")
        {
            cin>>key;
            s.push(key);
            order.insert(key);
        }
        else if(ope == "Pop" && !s.empty())
        {
            int val = s.top();
            cout<<val<<endl;
            s.pop();
            order.erase(val);
        }
        else if(ope == "PeekMedian")
        {
            if(order.empty())
            cout<<"Invalid"<<endl;
            else
            {
                int num = s.size();
                num = (num%2 == 0)? num/2 : (num+1)/2;
                auto it = order.begin();
                cout<<(*it+num-1)<<endl;
            }
        }
        else
        {
            cout<<"Invalid"<<endl;
        }
    }
    return 0;
 } 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用matlab 实现通信仿真
    • ¥15 按键修改电子时钟,C51单片机
    • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
    • ¥20 5037端口被adb自己占了
    • ¥15 python:excel数据写入多个对应word文档
    • ¥60 全一数分解素因子和素数循环节位数
    • ¥15 ffmpeg如何安装到虚拟环境
    • ¥188 寻找能做王者评分提取的
    • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
    • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件