A maintainer cannot do everything at once. Put the backlog in order of importance.
What to build
A program that scores issues and prints the five most important.
Requirements
- Each line is
ID|LABEL|REACTIONS. The score of an issue is the weight of its label plus the number of reactions. The weights aresecurity10,bug5,feature2,docs1; any other label weighs 0. - Sort by score from high to low and, for equal scores, by smaller ID first.
- Print the first 5 as
#ID score S. If there are fewer than 5 issues, print them all.
Input
The first line has n (1 to 100). Each of the next n lines is ID|LABEL|REACTIONS with whole numbers for ID and REACTIONS.
Output
Up to 5 lines.
Constraints
1 ≤ n ≤ 100.
Example
Input:
4
10|bug|2
11|feature|9
12|security|0
13|docs|1
Output:
#11 score 11
#12 score 10
#10 score 7
#13 score 2
Why it works
A single score combines the label and the user interest, and sorting by that score with the ID as a tie-breaker gives a stable, repeatable order; comparing numbers instead of text keeps ID 9 before ID 10.
Examples
4 10|bug|2 11|feature|9 12|security|0 13|docs|1
#11 score 11 #12 score 10 #10 score 7 #13 score 2
2 5|question|0 4|question|0
#4 score 0 #5 score 0
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Give each label a weight in a dictionary and use 0 for any other label.
Hint 2
Sort with key=lambda t: (-score, id), using the numbers, not text.
Hint 3
Print only the first 5 issues.
Solution
Show one correct solution (try it yourself first)
WEIGHT = {"security": 10, "bug": 5, "feature": 2, "docs": 1}
n = int(input())
rows = []
for _ in range(n):
issue, label, reactions = input().split("|")
rows.append((WEIGHT.get(label, 0) + int(reactions), int(issue)))
rows.sort(key=lambda r: (-r[0], r[1]))
for score, issue in rows[:5]:
print(f"#{issue} score {score}")
▶ Open this solution in the compiler, then press Visualize to watch it run step by step