fork download
  1. #include <iostream>
  2. #include <set>
  3.  
  4. using namespace std;
  5.  
  6. typedef pair<long, short> scorepair;
  7.  
  8. int main()
  9. {
  10. long nStudent, id, i;
  11. short score;
  12.  
  13. struct cmp
  14. {
  15. bool operator()(const scorepair &a, const scorepair &b)
  16. {
  17. return a.second == b.second ? a.first < b.first : a.second < b.second;
  18. }
  19. };
  20.  
  21. set<scorepair, cmp> scores;
  22. set<scorepair>::reverse_iterator it;
  23.  
  24. cin >> nStudent;
  25.  
  26. for(i = 0; i < nStudent; i++)
  27. {
  28. cin >> id >> score;
  29.  
  30. scores.insert(scorepair(id, score));
  31. }
  32.  
  33. i = 0;
  34. for(it = scores.rbegin(); it != scores.rend(); it++, i++)
  35. {
  36. cout << "Peringkat " << i + 1 << ": Absen " << it->first << " Nilai " << it->second << endl;
  37. }
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 16064KB
stdin
5
34 51
3 97
21 100
2 100
11 55
stdout
Peringkat 1: Absen 21 Nilai 100
Peringkat 2: Absen 2 Nilai 100
Peringkat 3: Absen 3 Nilai 97
Peringkat 4: Absen 11 Nilai 55
Peringkat 5: Absen 34 Nilai 51