### arham___khan's blog

By arham___khan, history, 2 months ago,

If I have a map<string,pair<int,int>> and I want to sort it in three different ways. 1.Sort by key. 2.Sort by value of first element in the pair. 3.Sort by value of second element in the pair.

Example : if mp [ {a,{9,7}} {y,{2,5}} {g,{3,1}} {i,{6,6}} {e,{1,2}} ]

1.Sort by key:
2.Sort by value of first element in the pair:
3.Sort by value of second element in the pair:

#### How to implement the above-mentioned three ways of sorting?

• -9

 » 2 months ago, # |   +9 Elements in the map are sorted by default by the key.you can't change its order
•  » » 2 months ago, # ^ |   0 Then how do I sort the list?
•  » » » 2 months ago, # ^ |   0 use a vector>>
•  » » » » 2 months ago, # ^ |   0 Using vector> is working fine for me with custom comparator. Thanks for the help though
 » 2 months ago, # |   0 I think you are writing this post after thinking implementation of Div3 B2 Problem. Am I right ? Yes I am also trying to get the same answer I will be following this post to get those answer. : — )
•  » » 2 months ago, # ^ |   0 NO there was a question related to this in my Amazon exam.
 » 2 months ago, # | ← Rev. 3 →   0 Hello! I would recommend you implementing by this way, by vector of pairs and comparators. The link: https://pastebin.com/f2bUv82W. I hope that I helped you.
•  » » 2 months ago, # ^ |   0 Really helpful thanks!!
 » 2 months ago, # |   0 hey can someone help me with this problem? https://codeforces.com/contest/143/problem/A this is my solution https://pastebin.com/ViwFKvWP
•  » » 2 months ago, # ^ | ← Rev. 2 →   0 You should make your own post describing in short: what have you learned from editorial to this contest and other participants solutions why it doesn't suit you what is your approach and what's your problem in this problem
 » 2 months ago, # |   +3 Instead of having this convoluted of a data structure, try to come up with a better way of implementing all around.
 » 2 months ago, # | ← Rev. 2 →   0 Check out my solution . its simple than u r thinking, MY IMPLEMENTATION for problem 1551 B2 any suggestions to make my solution cleaner are appreciated