Kodewick
Start learning →
Mini challenge←→0 / 60

Letter sign

#055Mini challengeMapsStrings6 min

The shop is putting up a light-up letter sign, one light per letter, and capitals use the same light as small letters. Write letters_needed(sign) to count how many of each letter (made lower case) it needs. Spaces, digits and punctuation need no light: skip them.

Examples
letters_needed("Hi Mom")→{'h': 1, 'i': 1, 'm': 2, 'o': 1}
letters_needed("")→{}
The functionmap<char, int> letters_needed(const string &sign)
main.cpp
#include <cctype>
#include <map>
#include <string>
using namespace std;

map<char, int> letters_needed(const string &sign) {
    map<char, int> need;
    for (char ch : sign) {
        // your code here: if it's a letter, lower-case it and add 1
    }
    return need;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.