提交时间:2024-08-20 16:03:21

运行 ID: 169260

#include <iostream> #include <bits/stdc++.h> using namespace std; const int MAX_DIGITS = 1005; void addArrays(int a[], int b[], int result[]) { int carry = 0; for (int i = 0; i < MAX_DIGITS; i++) { int sum = a[i] + b[i] + carry; result[i] = sum % 10; carry = sum / 10; } } int main() { int n; cin >> n; int values[MAX_DIGITS] = {0}; int contribution[MAX_DIGITS] = {0}; int totalContribution[MAX_DIGITS] = {0}; for (int i = 0; i < n; i++) { cin >> values[i]; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = j + 1; k < n; k++) { contribution[0] = values[i] + values[j] + values[k]; addArrays(totalContribution, contribution, totalContribution); } } } int i = MAX_DIGITS - 1; while (i > 0 && totalContribution[i] == 0) { i--; } for (; i >= 0; i--) { cout << totalContribution[i]; } cout << endl; return 0; }