L - Второй максимум

mail@pastecode.io avatar
unknown
c_cpp
7 months ago
495 B
12
Indexable
Never
#include <bits/stdc++.h>

using namespace std;

int main() {
    int max1, max2;
    cin >> max1 >> max2;
    if (max1 < max2) {
        swap(max1, max2);
    }
    
    while (true) {
        int x;
        cin >> x;
        if (x == 0) {
            break;
        }
        
        if (x >= max1) {
            max2 = max1;
            max1 = x;
        } else if (x > max2) {
            max2 = x;
        }
    }
    
    cout << max2;
    return 0;
}




Leave a Comment