Advertisement
anhkiet2507

PHAN TU NHO THU K

Oct 4th, 2021
2,615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6. using namespace std;
  7. void Sort(int arr[], int n){
  8.     for(int i = 0; i < n - 1; i++){
  9.         for(int j = i + 1; j < n; j++){
  10.             if(arr[i]>arr[j]){
  11.                 int temp = arr[i];
  12.                 arr[i] = arr[j];
  13.                 arr[j] = temp;
  14.             }
  15.         }
  16.     }
  17. }
  18. int main(){
  19.     int t;
  20.     cin >> t;
  21.     while(t--){
  22.         int n, k;
  23.         cin >> n >> k;
  24.         int arr[n];
  25.         for(int i = 0 ; i < n; i++){
  26.             cin >> arr[i];
  27.         }
  28.         sort(arr, arr+n); // Version 1
  29.         Sort(arr, n); // Version 2
  30.         cout << arr[k-1] << endl;
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement