Advertisement
123Vadim123

Untitled

Feb 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4.  
  5. using namespace std;
  6. // 3 макс элемента
  7. int main(){
  8. int n;
  9. cin >> n;
  10. vector <int> v(n);
  11. for (int i=0; i < n; i++)
  12. cin >> v[i];
  13. int a=v[0];
  14. int b=v[1];
  15. int c=v[2];
  16. int max1;
  17. int max2;
  18. int max3;
  19. if (a>b){
  20. if (a>c){
  21. max1=a;
  22. if (b>c){
  23. max2=b;
  24. max3=c;
  25. }
  26. else{
  27. max2=c;
  28. max3=b;
  29. }
  30. }
  31. else{
  32. max1=c;
  33. max2=a;
  34. max3=b;
  35. }
  36. }
  37. else{
  38. if (b>c){
  39. max1=b;
  40. if (a>c){
  41. max2=a;
  42. max3=c;
  43. }
  44. else{
  45. max2=c;
  46. max3=a;
  47. }
  48. }
  49. else{
  50. max1=c;
  51. max2=b;
  52. max3=a;
  53. }
  54. }
  55. for(int i=3; i<n; i++){
  56. if (v[i]>max1){
  57. max3=max2;
  58. max2=max1;
  59. max1=v[i];
  60. }
  61. if (v[i]>max2 && v[i]<=max1){
  62. max3=max2;
  63. max2=v[i];
  64. }
  65. if (v[i]<=max2 && v[i]>max3)
  66. max3=v[i];
  67. }
  68. cout << max1 << endl;
  69. cout << max2 << endl;
  70. cout << max3 << endl;
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement