Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. // Max.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. // Bài 3 || Huỳnh Thế Anh
  3.  
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int arr[1000];
  10. int n;
  11. cin >> n;
  12. for (int i = 0; i < n; i++)
  13. {
  14. cin >> arr[i];
  15. }
  16.  
  17. // process
  18. int m1 = 0, m2 = 0, m3 = 0;
  19.  
  20.  
  21.  
  22. for (int i = 0; i < n; i++)
  23. {
  24. if (arr[i] > m1)
  25. {
  26. m3 = m2;
  27. m2 = m1;
  28. m1 = arr[i];
  29. }
  30. else if (arr[i] > m2)
  31. {
  32. m3 = m2;
  33. m2 = arr[i];
  34.  
  35. }
  36. else if ( arr[i] > m3) m3 = arr[i];
  37. }
  38.  
  39. cout << m1 << " " << m2 << " " << m3;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement