Today I was solving this problem: CodeChef: Practical coding for everyone
and I thought of doing it using maps with string as key and value in the map as pair ( pair consists of the number of occurrences of the string with bool 0 and bool 1)
And every time I encounter a string , if it is already in the map then I want to increase the number in the pair by 1 if it is not there I will insert the key and value pair in the map
I implemented this and here is my code :
It will be good if someone tells me how to access the first and the second element of pairs in map
If you use ., you are trying to access the member named “first” (or “second”) of the iterator object, which doesn’t exist.
If you use -> then you are dereferencing the iterator (to obtain a reference to the object the iterator is referring to) and then trying to access the member named “first”/"second" of that referred object, which does exist.
In other words, by convention, it->blah behaves like (*it).blah, as would be the case if you were dealing with pointers (also by convention, iterators are designed to look/ behave like pointers).