Advertisement
thiend17pm03

Cau3-Entry Test - ReactJS

Feb 19th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.      int n ,max1=-1e9,max2=-1e9,max3=-1e9 ;
  6.      cin>>n;// Nhap so luong phan tu
  7.      for(int i = 0;i<n;i++)
  8.         {
  9.             int temp;cin>>temp; //nhap cac phan tu khong trung nhau
  10.             if(temp <=max3) continue;
  11.             if(temp > max1)
  12.             {
  13.                 max3=max2;
  14.                 max2=max1;
  15.                 max1=temp;
  16.              }
  17.             else if(temp>max2)
  18.                     {
  19.                         max3=max2;
  20.                         max2=temp;
  21.                     }
  22.                  else
  23.                  {
  24.                     max3=temp;
  25.                  }
  26.            
  27.          }
  28.      
  29.     if(n==1) cout<<max1;
  30.     if(n==2) cout<<max1<<" "<<max2;
  31.     if(n>=3) cout<<max1<<" "<<max2<<" "<<max3;
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement