1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <iostream>
#include <algorithm>
int main () {
int max_sum = 0;
int min_sum = 9000000;
int array[] = {1,2,5,6,758};
//int array[] = {1, 2, 5, 6, 7, 5, 8, 15, 56, 14, 24, 4, 2, 19};
int length = sizeof(array)/sizeof(int);
std::sort(array, array + length);
int** sum_array = new int *[length];
for(int i = 0; i < length; ++i)
sum_array[i] = new int[length];
for (int row = 0; row < length; row++)
{
for( int col = 0; col < length; col++)
{
sum_array[row][col] = 0;
}
}
for (int row = 0; row < length; row++)
{
for( int col = 0; col < length; col++)
{
if( row != col)
{
sum_array[row][col] = array[row] + array[col];
if ( sum_array[row][col] > max_sum )
max_sum = sum_array[row][col];
if ( sum_array[row][col] < min_sum )
min_sum = sum_array[row][col];
}
}
}
int* sequence_array = new int[max_sum];
for (int row = 0; row < length; row++)
{
for( int col = 0; col < length; col++)
{
sequence_array[sum_array[row][col]] = 1;
}
}
for (int i = min_sum; i <= max_sum; i++)
{
if (sequence_array[i] == 0 )
{
std::cout << i << " <-- FIRST ... QED\n";
break;
}
}
for(int i = 0; i < length; ++i)
delete [] sum_array[i];
delete [] sum_array;
delete [] sequence_array;
return 0;
}
|