How to count how many times unique word appears

For one part of exercise I need to count how many areas there are:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
15
Vilnius             Vilniaus     541278
Dusetos             Utenos       4211  
Alytus              Alytaus      69859 
Druskininkai        Alytaus      16890 
Ignalina            Utenos       6307  
Kavarskas           Utenos       753   
Lazdijai            Alytaus      5027  
Simnas              Alytaus      1940  
Trakai              Vilniaus     5504  
Utena               Utenos       33086 
Veisiejai           Alytaus      1673  
Vievis              Vilniaus     5246  
Lentvaris           Vilniaus     11832 
Visaginas           Utenos       28438 
Zarasai             Utenos       8001  

Basically I have to count how many unique areas there are from the second block. The answer should be: Vilnius, Utenos, Alytaus - so 3. I know how count how many times each area appears, but I can't figure out how to do what they are asking of me. Keep it beginner friendly if possible.

Read the three strings off each line after the first (task 1).

Insert the second one from each line into a set<string> (task 2).

A set only holds unique items, so the number of distinct areas will be the size of the set.
Nice idea, lastchance. I’ve always managed this kind of problems with a std::map<std::string, int>, but your proposal is worth a try.
if you need to count "how many times a unique word appears" then use <map>
or if you need "how many unique areas are there" then use <set>
Registered users can post here. Sign in or register to post.