Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- using namespace std;
- // 3 макс элемента
- int main(){
- int n;
- cin >> n;
- vector <int> v(n);
- for (int i=0; i < n; i++)
- cin >> v[i];
- int a=v[0];
- int b=v[1];
- int c=v[2];
- int max1;
- int max2;
- int max3;
- if (a>b){
- if (a>c){
- max1=a;
- if (b>c){
- max2=b;
- max3=c;
- }
- else{
- max2=c;
- max3=b;
- }
- }
- else{
- max1=c;
- max2=a;
- max3=b;
- }
- }
- else{
- if (b>c){
- max1=b;
- if (a>c){
- max2=a;
- max3=c;
- }
- else{
- max2=c;
- max3=a;
- }
- }
- else{
- max1=c;
- max2=b;
- max3=a;
- }
- }
- for(int i=3; i<n; i++){
- if (v[i]>max1){
- max3=max2;
- max2=max1;
- max1=v[i];
- }
- if (v[i]>max2 && v[i]<=max1){
- max3=max2;
- max2=v[i];
- }
- if (v[i]<=max2 && v[i]>max3)
- max3=v[i];
- }
- cout << max1 << endl;
- cout << max2 << endl;
- cout << max3 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement