#include <stdio.h>
#include <string.h>
#include <queue>
#include <vector>
#define ll long long
struct Element {
int score;
char name[100];
Element(int s, const char* n) {
score = s;
strcpy(name, n);
}
bool operator<(const Element& autre) const {
if (score != autre.score) return (score < autre.score);
return false;
}
};
char str[100];
char INSTRUCTIONS[] = R"(
format d'entrée :
importance (de 0 à 10) urgence (de 0 à 10) nom de la tâche (longueur max = 100)
int int char[]
)";
int imp, u;
std::priority_queue<Element> pq;
static inline void print_queue(std::priority_queue<Element> copy) {
while (!copy.empty()) {
printf("importance*urgence : %d, tâche : %s\n", copy.top().score, copy.top().name);
copy.pop();
}
}
int main() {
printf("%s\n", INSTRUCTIONS);
while (true) {
printf("Nouvelle tâche > ");
fflush(stdout);
if (fgets(line, sizeof(line), stdin) == NULL) {
break;
}
if (sscanf(line, "%d %d %99[^\n]", &imp, &u, str) != 3) {
printf("Entrée invalide.\n");
continue;
}
if (imp < 0 || imp > 10 || u < 0 || u > 10) {
printf("Importance et urgence doivent être entre 0 et 10.\n");
continue;
}
pq.emplace(imp*u, str);
print_queue(pq);
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: