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.