[算法题]设我们有一些任务列表,任务编号从1开始(C++详细题解)

引言:设我们有一些任务列表,任务编号从1开始。不同的任务难度也不一样,分为1-5级。

题目

我们打算把这些任务分配给牛牛,可是牛牛比较懒,每次他接受到一个任务后,他都会从自己的todo list里找到“难度各不相同且编号和最大的五个任务”,然后再一起完成,否则的话,牛牛就把任务放到自己的todo list,什么也不做。
要求:请你根据输入的任务列表的情况,给出牛牛完成任务的情况。

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<string>

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    stack<int> st1;
    stack<int> st2;
    stack<int> st3;
    stack<int> st4;
    stack<int> st5;
    
    for(int i = 1; i <= n; i++)
    {
        int num;
        cin >> num;
        switch (num)
        {
         case 1:
               st1.push(i);
               break;
         case 2:
               st2.push(i);
               break;
         case 3:
               st3.push(i);
               break;
         case 4:
               st4.push(i);
               break;
         case 5:
               st5.push(i);
               break;
         default:
               break;
        }
        if(!st1.empty() && !st2.empty() && !st3.empty() && !st4.empty() && !st5.empty())
        {
            cout << st1.top() << " " << st2.top() << " " << st3.top() << " " << st4.top() << " " << st5.top() << endl;
            st1.pop();
            st2.pop();
            st3.pop();
            st4.pop();
            st5.pop();
        }
        else
            cout << -1 << endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值