第一个被处理的是哪个任务
四个任务和它们的优先级(数字越大越急)。运行下面这段程序:
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
struct Task {
int prio;
string name;
};
int main() {
vector<Task> tasks = {{2, "备份"}, {5, "告警"}, {1, "日报"}, {5, "扩容"}};
int best = 0;
for (int i = 1; i < (int)tasks.size(); i++) {
if (tasks[i].prio > tasks[best].prio) best = i;
}
cout << tasks[best].name << endl;
}
(本题用 g++ -std=c++17 -O0 编译。)
全部评论