Cod sursa(job #2098358)

Utilizator GoogalAbabei Daniel Googal Data 2 ianuarie 2018 18:39:36
Problema Prod Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream in("prod.in");
ofstream out("prod.out");

const int CMAX = 1000;

int ap[10];
int a[1 + CMAX];
int b[1 + CMAX];
int c[1 + CMAX * CMAX];

bool cmp() {
  if(a[0] != b[0])
    return a[0] < b[0];
  else {
    for(int i = a[0]; i >= 1; i--) {
      if(a[i] != b[i])
        return a[i] < b[i];
    }
  }

  return false;
}

int main()
{
  for(int i = 1; i <= 9; i++)
    in >> ap[i];

  for(int i = 9; i >= 1; i--) {
    for(int j = 1; j <= ap[i]; j++) {
      if(cmp() == true) // a is smaller than b
        a[++a[0]] = i;
      else // b is smaller than a
        b[++b[0]] = i;
    }
  }

  for(int i = a[0]; i >= 1; i--) {
    for(int j = b[0]; j >= 1; j--) {
      c[a[0] + b[0] - i - j + 1] += a[i] * b[j];
    }
  }

  c[0] = a[0] + b[0] - 1;
  int t = 0;
  int i = 1;
  while(i <= c[0] || t != 0) {
    c[i] += t;
    t = c[i] / 10;
    c[i] %= 10;
    i++;
  }

  c[0] = max(c[0], i - 1);
  for(int i = c[0]; i > 0; i--)
    out << c[i];
  out << '\n';

  in.close();
  out.close();
  return 0;
}