Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 months ago
1.0 kB
0
Indexable
Never
#include <iostream>
#include <vector>
#include <string>

using namespace std;

// Function to calculate the value of a string based on the rules given
long long calculateValue(string str) {
    long long value = 0;
    bool hasDigit = false;

    for (char c : str) {
        if (isdigit(c)) {
            value = value * 10 + (c - '0');
            hasDigit = true;
        }
    }

    if (!hasDigit) {
        value = str.length();
    }

    return value;
}

int main() {
    int n;
    cin >> n;

    vector<string> arr(n);

    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }

    long long max1 = 0, max2 = 0;

    for (int i = 0; i < n; ++i) {
        long long value = calculateValue(arr[i]);

        if (value > max1) {
            max2 = max1;
            max1 = value;
        } else if (value > max2) {
            max2 = value;
        }
    }

    long long maxProduct = max1 * max2;
    cout << maxProduct << endl;

    return 0;
}