020-003-006

Collections: Key-Value Management with HashMap

Hard

Problem Description

Collections: Key-Value Management with HashMap

In this problem, you will create a program that registers student names and scores into a HashMap, then displays the map's size and the result of searching for a specific key to standard output.

Learning Objective: Understand key-value pair management using HashMap

Overview

HashMap holds key-value pairs. You can quickly retrieve values by specifying keys. Also called dictionary or associative array.

Specifications

Create a program to manage student names and scores.

  • First input: Number of students n to register
  • Next n lines: Each line contains name and score separated by space
  • Output Map size
  • Output specific student's ("Alice") score
    • If exists: "Alice: "
    • If not exists: "Alice: Not found"

Input Format

<student count>
<name1> <score1>
<name2> <score2>
...

Output Format

Size: <size>
Alice: <score or "Not found">

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up