arham___khan's blog

By arham___khan, history, 3 years ago, In English

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?

  • Vote: I like it
  • -9
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +9 Vote: I do not like it

Elements in the map are sorted by default by the key.

you can't change its order

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

hey can someone help me with this problem? https://codeforces.com/contest/143/problem/A this is my solution https://pastebin.com/ViwFKvWP

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    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
»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Instead of having this convoluted of a data structure, try to come up with a better way of implementing all around.