【題解】ZeroJudge a825: 3.小四數學

題目敘述:https://zerojudge.tw/ShowProblem?problemid=a825

#include <iostream>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    int n;
    while (cin >> n){
        int x = 0, y = 0, a[n];
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        sort(a, a+n);
        for (int i = n-1; i >= 0; i--){
            if (x <= y){
                x *= 10;
                x += a[i];
            }else{
                y *= 10;
                y += a[i];
            }
        }
        cout << x * y << endl;
    }
}
分享本文 Share with friends