Advertisement
LEGEND2004

vector

Feb 15th, 2024
1,057
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  6. const int N = 1e6 + 5;
  7. int a[N]; // static array
  8.  
  9.  
  10.  
  11. signed main()
  12. {
  13.     fastio;
  14.  
  15.     // Dynamic arrays
  16.     /*
  17.     vector<int> v; // {} <---
  18.     //vector<int> v(3 , 5); // {5 , 5 , 5}
  19.     v.push_back(5); // {5}
  20.     v.push_back(3); // {5 , 3}
  21.     cout << v.back() << '\n'; // en sagdaki element
  22.     v.pop_back(); // en sagdakini sil
  23.     v.clear(); // butun vektoru sil v.size() = 0
  24.     cout << v.size(); // olcusu
  25.     if(v.empty()) // eger bosdursa v.size() == 0
  26.     */
  27.     int n;
  28.     cin >> n;
  29.     vector<int> a(n);
  30.     for(int i = 0; i < n; i++){
  31.         cin >> a[i];
  32.     }
  33.     //sort(a + 0, a + n); // [0 , n - 1]
  34.     sort(a.begin() , a.end()); // [begin() , end() - 1]
  35.     reverse(a.begin() , a.end());
  36.     cout << a[0] << ' ';
  37.     cout << a.back() << '\n';
  38.     //cout << *(a.begin() + i);
  39.     for(int i = 0; i < a.size(); i++){
  40.         cout << a[i] << ' ';
  41.     }
  42.     cout << '\n';
  43.     for(int i : a){
  44.         cout << i << ' ';
  45.     }
  46.     cout << '\n';
  47.     // {5 , 3}
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement