|
- #include <iostream>
- #include <string>
- #include <algorithm>
- #define MAXN 100
- using namespace std;
- typedef struct num {
- int data[MAXN];
- };
- void input_num(num &a)
- {
- string s;
- cin >> s;
- for (int i = 0; i != s.size(); ++i) {
- a.data[i] = int(s[i]) - 48;
- }
- }
- void output_num(num a)
- {
- int i = MAXN;
- while (a.data[i] == 0)
- --i;
- while (i >= 0)
- cout << a.data[i];
- }
- bool comp_num(num a, num b) {
- int i = MAXN;
- int j = MAXN;
- while (a.data[i] == 0)
- --i;
- while (b.data[j] == 0)
- --j;
- if (i < j)
- return true;
- else if (i > j)
- return false;
- else {
- while (i >= 0) {
- if (a.data[i] < b.data[i])
- return true;
- else if (a.data[i] > b.data[i])
- return false;
- else
- --i;
- }
- return true;
- }
- }
- void plus_num(num &a, num b)
- {
- int x = 0;
- for (int i = 0; i != MAXN; ++i) {
- a.data[i] += b.data[i];
- a.data[i] += x;
- x = a.data[i] / 10;
- a.data[i] %= 10;
- }
- }
- void minus_num(num &a, num b)
- {
-
- }
- num x[10000];
- num tot;
- int n;
- int main()
- {
- cin >> n;
- for (int i = 0; i != n; ++i)
- input_num(x[i]);
- sort(x, x + n, comp_num);
- for (int i = 0; i != n; ++i) {
- for (int j = i + 1; j != n; ++j) {
- num y;
- for (int k = 0; k != MAXN; ++k)
- y.data[k] = x[j].data[k];
- minus_num(y, x[i]);
- plus_num(tot, y);
- tot += ((x[j] - x[i]) * 2);
- }
- }
- output(tot);
- return 0;
- }
复制代码 |
|