Advertisement
otot957

Untitled

Feb 13th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. /*
  4. multiplying 3 numbers from an array to get highest product possible
  5.  
  6. */
  7.  
  8.  
  9. int m1, m2, m3;
  10. bool comp(int a, int b){
  11.   if(m1 && !m2)
  12.   {
  13.     if(a < m1 && b< m1)
  14.       return (a <b);
  15.     else if (a==m1 || b==m1)
  16.       return false;
  17.   }
  18.   if(m1 && m2){
  19.     if(a < m1 && a< m2 && b< m1 && b<m2){
  20.       return (a<b);
  21.     }
  22.     else if(a==m1 || a== m2 || b==m1 || b==m2)
  23.       return false;
  24.   }
  25.  
  26. }
  27.  
  28. int main(){
  29.   vector<int> vect= {2,3,6,9,12,15};
  30.   m1=0, m2=0, m3=0;
  31.   m1= *max_element(vect.begin(), vect.end());
  32.   m2= *max_element(vect.begin(), vect.end(), comp);
  33.   cout<<m2<<endl;
  34.   m3= *max_element(vect.begin(), vect.end(), comp);
  35.   cout<<m3*m1*m2<<endl;
  36.   return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement