Advertisement
RobertDeMilo

WB3.1 Функции min, max, sort

Sep 4th, 2023
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. void Print(const vector <int>& v, const string& title)
  10. {
  11.     cout << title << ": ";
  12.     for (auto i : v)
  13.     {
  14.         cout << i << ' ';
  15.     }
  16. }
  17.  
  18. int main()
  19. {
  20.     string s1 = "abc";
  21.     string s2 = "bca";
  22.  
  23.     cout << min(s1, s2) << endl;
  24.     cout << max(s1, s2) << endl;
  25.    
  26.     cout << min(2, 3) << endl;
  27.     cout << max(2, 3) << endl;
  28.  
  29.     vector<int> v = { 1,3,5,2,4 };
  30.     Print(v, "init");
  31.    
  32.     sort(begin(v), end(v));
  33.     cout << endl;
  34.    
  35.     Print(v, "sort");
  36.  
  37.     return 0;
  38. }
Tags: Max sort Min
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement