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
| #include<vector>
#include<iostream>
using namespace std;
int main(int argc, char* argv[])
{
// XXX TODO: Need to initialize vector list
unsigned char list_c[] = {7,3,1,6,7,1,7,6,5,3,1,3,3,0,6,2,4,9,1,9,2,2,5,1,1,9,6,7,4,4,2,6,5,7,4,7,4,2,3,5,5,3,4,9,1,9,4,9,3,4};
vector<unsigned char> list(list_c, list_c + sizeof(list_c) / sizeof(list_c[0]));
if (list.size() < 5) { return 1; }
// Circular array
unsigned char last_5_numbers[5] = {0, 0, 0, 0, 0};
unsigned char last_index = 0;
unsigned short current_product = 0, max_product = 0;
for(vector<unsigned char>::iterator it = list.begin(); it != list.end(); ++it, last_index = ((last_index + 1) % 5)) {
last_5_numbers[last_index] = *it;
current_product = last_5_numbers[0] * last_5_numbers[1] * last_5_numbers[2] * last_5_numbers[3] * last_5_numbers[4];
if (current_product > max_product) { max_product = current_product; }
cout << (unsigned int) last_5_numbers[last_index] << ", current: " << current_product << ", max: " << max_product << endl;
}
return 0;
} |
Partager