fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <functional>
  5.  
  6. typedef std::pair<int, int> parInts;
  7.  
  8. bool comparador (parInts ponto1, parInts ponto2){
  9. if (ponto1.first == ponto2.first){
  10. return ponto1.second > ponto2.second;
  11. }
  12. else {
  13. return ponto1.first > ponto2.first;
  14. }
  15. }
  16.  
  17. int main () {
  18. std::priority_queue<parInts, std::vector<parInts>, std::function<bool(parInts, parInts)>> fila(comparador);
  19.  
  20. fila.push(std::make_pair(5, 1));
  21. fila.push(std::make_pair(3, 2));
  22. fila.push(std::make_pair(6, 3));
  23. fila.push(std::make_pair(3, 4));
  24.  
  25. while (!fila.empty()){
  26. std::pair<int, int> ponto = fila.top();
  27. std::cout << ponto.first << " " << ponto.second << std::endl;
  28. fila.pop();
  29. }
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
3 2
3 4
5 1
6 3