Advertisement
catalyn

prb 8.12.2015

Dec 8th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. //se citesc n nr naturale ..sa se afiseze cele mai mari 3 nr pare
  2. #include <iostream>
  3. #include<climits>
  4. int n,m1=INT_MIN,m2=INT_MIN,m3=INT_MIN;
  5.  
  6. using namespace std;
  7. void sortare()
  8. {
  9. if(m1>m2)
  10. swap(m1,m2);
  11. if(m1>m3)
  12. swap(m1,m3);
  13. if(m2>m3)
  14. swap(m2,m3);
  15. }
  16.  
  17. void greedy()
  18. {
  19. int x,i;
  20. for(i=1;i<=n;i++)
  21. {
  22. cin>>x;
  23. if(x%2==0)
  24. {
  25. if(x>m1)
  26. m1=x;
  27. sortare();
  28. }
  29. }
  30. }
  31. int main()
  32. {
  33. cin>>n;
  34. greedy();
  35. if(m1==INT_MIN || m2==INT_MIN || m3==INT_MIN)
  36. cout<<"Nu exista";
  37. else
  38. cout<<m1<<" " <<m2<<" "<<m3;
  39.  
  40.  
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement