Untitled

 avatar
unknown
c_cpp
2 years ago
1.2 kB
5
Indexable
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int calculateValue(string s) {
    // If there are digits in the string, concatenate them and convert to an integer.
    string digits = "";
    for (char c : s) {
        if (isdigit(c)) {
            digits += c;
        }
    }
    if (!digits.empty()) {
        return stoi(digits);
    }
    // If there are no digits, return the length of the string.
    return s.length();
}

int maxProductOfValues(vector<string>& arr) {
    int n = arr.size();
    int maxProduct = 0;

    // Iterate through the array to calculate values and find the maximum product.
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int product = calculateValue(arr[i]) * calculateValue(arr[j]);
            maxProduct = max(maxProduct, product);
        }
    }

    return maxProduct;
}

int main() {
    int n;
    cin >> n;
    vector<string> arr(n);

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

    // Calculate and print the maximum product of values
    int result = maxProductOfValues(arr);
    cout << result << endl;

    return 0;
}
Editor is loading...