[算法题]设我们有一些任务列表,任务编号从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;
}
2301_81472921: 好神奇 我也能打开了
m0_73363521: 递归开始为啥l=n,r=0,而不是都是n?
m0_73363521: 37行笔误,loc==l应该是loc==i
٩(ˊvˋ*)و。。。: 博主还在更新嘛
m0_74112540: 请问有完整代码吗