Lesson 13 of 24

map, unordered_map

10 min 35 XP

map ഓരോ key-ക്കും value സൂക്ഷിക്കുന്നു, keys sorted ആയിരിക്കും (O(log n)). unordered_map-ന് ക്രമമില്ല, പക്ഷേ ശരാശരി O(1). എണ്ണൽ m[key]++ പോലെ ലളിതമാണ്.

Example: edit me and press Run

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.

for (auto& [key, value] : m) C++17 structured bindings ഉപയോഗിക്കുന്നു. m[key] വായിക്കുമ്പോൾ key ഇല്ലെങ്കിൽ 0 ആയി ചേർക്കപ്പെടും; പരിശോധിക്കാൻ മാത്രം count() അല്ലെങ്കിൽ find() ഉപയോഗിക്കൂ.

Challenge

+35 XP

n-ഉം പിന്നെ n വാക്കുകളും വായിക്കൂ. ഓരോ വാക്കും എത്ര തവണ വന്നുവെന്ന് അക്ഷരമാല ക്രമത്തിൽ print ചെയ്യൂ. Input: 6 apple mango apple kiwi mango apple Output: apple 3 kiwi 1 mango 2

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.