Advertisement
Josif_tepe

Untitled

Feb 21st, 2025
311
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 <vector>
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8.     int n;
  9.     cin >> n;
  10.    
  11.     int niza[n];
  12.     for(int i = 0; i < n; i++) {
  13.         cin >> niza[i];
  14.     }
  15.    
  16.     for(int i = 0; i  < n; i++) {
  17.         for(int j = i + 1; j < n; j++) {
  18.             if(niza[i] > niza[j]) {
  19.                 swap(niza[i], niza[j]);
  20.             }
  21.         }
  22.     }
  23.    
  24.     int najgolem = n - 1;
  25.     int najmal = 0;
  26.    
  27.     while(najgolem >= najmal) {
  28.         cout << niza[najgolem] << " ";
  29.         najgolem--;
  30.        
  31.         if(najgolem >= najmal) {
  32.             cout << niza[najmal] << " ";
  33.             najmal++;
  34.         }
  35.     }
  36.    
  37.    
  38.    
  39.    
  40.     return 0;
  41. }
  42.  
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement