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.