Pagini recente » Diferente pentru home intre reviziile 501 si 500 | Istoria paginii utilizator/raluca1234 | Istoria paginii utilizator/cnnon | Cod sursa (job #241714) | Cod sursa (job #466943)
Cod sursa(job #466943)
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <ctime>
#include <bitset>
#include <deque>
#include <fstream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef bool int01;
typedef char cha08;
typedef short int int16;
typedef int int32;
typedef float rea32;
typedef long long int int64;
typedef double rea64;
const cha08 Input[] = "prod.in";
const cha08 Output[] = "prod.out";
const int32 Dim = 1001;
int32 A[Dim], B[Dim];
int32 f[10];
int32 Cmp( int32 A[], int32 B[] ) {
int32 i;
if( A[0] < B[0] )
return -1;
if( A[0] > B[0] )
return 1;
for( i = A[0]; i >= 1; --i ) {
if( A[i] < B[i] )
return -1;
if( A[i] > B[i] )
return 1;
}
return 0;
}
void Ins( int32 A[], int32 B ) {
int32 i;
for( i = ++A[0]; i >= 2; --i )
A[i] = A[i - 1];
A[1] = B;
}
void Mul( int32 A[], int32 B[] ) {
int32 C[Dim];
int32 i, j, t;
memset( C, 0, sizeof( C ) );
for( i = 1; i <= A[0]; ++i ) {
for( j = 1, t = 0; j <= B[0] || t; ++j, t /= 10 )
C[i + j - 1] = (t += C[i + j - 1] + A[i] * B[j]) % 10;
if( i + j - 2 > C[0] )
C[0] = i + j - 2;
}
memcpy( A, C, sizeof( C ) );
}
int32 main() {
ifstream fin( Input );
ofstream fout( Output );
int32 i;
for( i = 1; i <= 9; ++i )
fin >> f[i];
for( i = 9; i >= 1; --i )
if( f[i] ) {
Ins( A, i );
--f[i];
break;
}
for( i = 9; i >= 1; --i )
if( f[i] ) {
Ins( B, i );
--f[i];
break;
}
for( i = 9; i >= 1; ) {
if( !f[i] ) {
--i;
continue;
}
if( A[0] < B[0] ) {
Ins( A, i );
--f[i];
}
if( B[0] < A[0] ) {
Ins( B, i );
--f[i];
}
while( f[i] >= 2 ) {
Ins( A, i );
Ins( B, i );
f[i] -= 2;
}
if( f[i] ) {
if( Cmp( A, B ) < 0 ) {
Ins( A, i );
--f[i];
}
else {
Ins( B, i );
--f[i];
}
}
}
// for( int32 i = A[0]; i >= 1; --i )
// fout << A[i];
// fout << "\n";
// for( int32 i = B[0]; i >= 1; --i )
// fout << B[i];
// fout << "\n";
Mul( A, B );
for( i = A[0]; i >= 1; --i )
fout << A[i];
fin.close();
fout.close();
return 0;
}