Map (Key-Value Dictionary)

Medium STL Containers
Solve in Playground →

Problem Statement

Write a C++ program using `std::map` to count word frequencies and print them sorted by keys.

Input Format

First line: N. Next N lines: string keys.

Output Format

Print key and frequency pairs row by row.

Constraints

1 <= N <= 100

Sample Input

4
apple
banana
apple
cherry

Sample Output

apple: 2
banana: 1
cherry: 1

Explanation

Maps store key-value pairs sorted automatically by unique keys.

Starter Code

#include <iostream>
#include <map>
#include <string>

int main() {
    int n;
    if (std::cin >> n) {
        std::map<std::string, int> freq;
        for (int i = 0; i < n; i++) {
            std::string s;
            std::cin >> s;
            freq[s]++;
        }
        // Write your map output logic here

    }
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used