EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • 🇲🇾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🥰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. ABaKoDa
  2. 2023
  3. Round 1

Rankings Order

https://codeforces.com/group/cRJbcAFEwS/contest/485694/problem/C

Question

Abby and Cody want to make a new website called Abakoda, where beginner programmers can join friendly programming contests and improve their skills.

Now they are working on displaying the contest rankings. They need to display the contestants ordered by rank.

Name
Total
A
B
K
D

Abby

400

100

100

100

100

Cody

300

100

100

100

0

Aba

200

100

0

100

0

Koda

100

100

0

0

0

Solved By

4

2

3

1

Abby and Cody need your help. They already wrote code that displays the name and total score of each contestant. Write a program that displays the names in order, from highest to lowest score. Ties are broken by alphabetical order: the contestant whose name comes first by alphabetical order gets shown first.

Input Format

The input contains several lines.

The first line of input contains one integer nnnn, the number of contestants.

This is followed by nnnn lines of input. Each of these lines contains a name and a score, separated by a space, representing the name and score of a single contestant. The name contains only lowercase English letters, no spaces, and no punctuation marks. Each name contains at least one letter. The score is one of the following: 000, 100100100, 200200200, 300300300, or 400400400.

Constraints

1≤n≤1051 \le n \le 10^51≤n≤105
  • No two contestants have the same name.

  • The length of each name does not exceed 10.

Output Format

Your program must print nnn lines of output. Each line must contain a name and a score, in that order, separated by a space. These lines must contain the same data as in the input but in the right order.

Sample Inputs:

Input

4
aba 200
abby 400
koda 100
cody 300

Output

abby 400
cody 300
aba 200
koda 100

Explanation:

In the first sample test case, there are four contestants.

  • Contestant aba has 200 points.

  • Contestant abby has 400 points.

  • Contestant koda has 100 points.

  • Contestant cody has 300 points.

They should appear in the rankings in the following order:

  1. abby

  2. cody

  3. aba

  4. koda

Input

2
cody 400
abby 400

Output

abby 400
cody 400

Explanation

Note that ties are broken by alphabetical order.


Solution — Simple ranking with lambda

The difficulty spikes upward that requires lambda function to solve wtf

We can know that this is a double-sorting system, which scores takes precedence, and the letter next.

By looping and doing some simple iteration sorting, this coding should be done in no issue.

Here's the solution:

counter = int(input())
score_list = {}

for i in range(0, counter):
    name, score = input().split()
    score = int(score)
    if name in score_list and score_list[name] < score:
        score_list[name] = score
    elif name not in score_list:
        score_list[name] = score

sorted_scores = sorted(score_list.items(), key=lambda x: (-x[1], x[0]))

for name, score in sorted_scores:
    print(name, score)

PreviousProblem StatisticsNextRankings Search

Last updated 2 months ago

Page cover image