fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <time.h>
  5.  
  6. using namespace std;
  7.  
  8. int n,w;
  9. int *liczba=new int [n];
  10. char *litera=new char [n];
  11.  
  12. void quick_sort(int left, int right)
  13. {
  14. int i,j,piwot;
  15. char piwotch;
  16. i = (left + right) / 2;
  17. piwot = liczba[i]; liczba[i] = liczba[right];
  18. piwotch = litera[i]; litera[i] = litera[right];
  19. for(j = i = left; i < right; i++)
  20. if(liczba[i] < piwot)
  21. {
  22. swap(liczba[i], liczba[j]);
  23. swap(litera[i], litera[j]);
  24. j++;
  25. }
  26. liczba[right] = liczba[j]; liczba[j] = piwot;
  27. litera[right] = litera[j]; litera[j] = piwotch;
  28. if(left < j - 1) quick_sort(left, j - 1);
  29. if(j + 1 < right) quick_sort(j + 1, right);
  30. }
  31.  
  32. int main()
  33. {
  34. cin>>n;
  35.  
  36. for(int i = 0; i < n; i++){
  37. cin>>liczba[i];
  38. cin>>litera[i];
  39. }
  40.  
  41. cin>>w;
  42. quick_sort(0,n-1);
  43. for(int i = n-1; i >= n-w; i--){
  44. cout << litera[i];
  45. if (i!= n-w) cout<<endl;
  46. }
  47. return 0;
  48. }
Success #stdin #stdout 0s 15240KB
stdin
5
2 a
3 b
4 c
1 d
3 f
3
stdout
c
f
b