Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <functional>
  5. #include <cstdlib>
  6. #include <ctime>
  7.  
  8.  
  9.     using namespace std;
  10.     int main()
  11.     {
  12.         srand(time(NULL));
  13.  
  14.         vector <int> v, t(10);
  15.         vector <int> ::iterator imax, pos;
  16.         int n = 10;
  17.         // Формування вектора
  18.         for (int i = 0; i < n; ++i)
  19.             v.push_back(rand() % 90 - 2);
  20.         cout << "Sformovanuj vector\n" << endl;
  21.         for (pos = v.begin(); pos != v.end(); ++pos)
  22.             cout << *pos << " " << endl;
  23.  
  24.         imax = max_element(v.begin(), v.end());
  25.         cout << "\nMax element: " << *imax << endl;
  26.  
  27.         // Визначення позиції максимального елемента
  28.         imax = find(v.begin(), v.end(), *imax);
  29.         cout << "Pozuciya max elementa: " << imax - v.begin() << endl;
  30.  
  31.        
  32.        
  33.         for (int i = 0; i < n; i++) {
  34.             if (v[i] == 0){
  35.    
  36.                 int leftPart = 1;
  37.                 int rightPart = 1;
  38.                
  39.                 if(i > 0){
  40.                     leftPart = v[i-1]; 
  41.                 }
  42.                
  43.                 if(i != n-1){
  44.                     rightPart = v[i+1];
  45.                 }
  46.                
  47.                 cout << "Dobutok both parts = " << leftPart*rightPart << endl;
  48.                
  49.             }
  50.         }
  51.  
  52.        
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement