Untitled

 avatar
unknown
c_cpp
a year ago
1.2 kB
3
Indexable
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

// Function to calculate the value of a string based on the rules given
int calculateValue(string str) {
    int value = 0;
    for (char c : str) {
        if (isdigit(c)) {
            value = value * 10 + (c - '0');
        } else {
            value = str.length();
            break;
        }
    }
    return value;
}

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

    // Calculate the values of all strings and store them in a separate array
    vector<int> values(n);
    for (int i = 0; i < n; ++i) {
        values[i] = calculateValue(arr[i]);
    }

    // Find the two maximum values
    int max1 = 0, max2 = 0;
    for (int i = 0; i < n; ++i) {
        if (values[i] > values[max1]) {
            max2 = max1;
            max1 = i;
        } else if (values[i] > values[max2]) {
            max2 = i;
        }
    }

    // Calculate and print the maximum product of values
    long long maxProduct = 1LL * values[max1] * values[max2];
    cout << maxProduct << endl;

    return 0;
}