fork download
  1. #include <stdio.h>
  2.  
  3. struct Person {
  4. char id;
  5. int salary;
  6. };
  7.  
  8.  
  9. typedef struct Person Person;
  10.  
  11. int main() {
  12. Person p[10];
  13. int n;
  14. scanf("%d", &n);
  15. for (int i = 0; i < n; i++) {
  16. scanf(" %c", &p[i].id);
  17. scanf("%d", &p[i].salary);
  18. }
  19.  
  20.  
  21. int min;
  22. int temp;
  23. char ch;
  24.  
  25.  
  26. for (int i = 0; i < n; i++) {
  27. min = i;
  28.  
  29. for (int m = i + 1; m < n; m++) {
  30. if (p[m].salary < p[min].salary) {
  31. min = m;
  32. temp = p[m].salary;
  33. p[m].salary = p[min].salary;
  34. p[min].salary = temp;
  35. ch = p[m].id;
  36. p[m].id = p[min].id;
  37. p[min].id = ch;
  38. }
  39. }
  40. }
  41. for (int i = n - 1; i >= 0; i--) {
  42. printf("%c ", p[i].id);
  43. printf("%d\n", p[i].salary);
  44. }
  45. return 0;
  46. }
Success #stdin #stdout 0s 5268KB
stdin
7
q
5026
z
3019
r
4488
4
6125
k
7719
l
8136
m
9999
stdout
m 9999
l 8136
k 7719
4 6125
r 4488
z 3019
q 5026