-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc2009_preamble.cpp
78 lines (67 loc) · 2.42 KB
/
aoc2009_preamble.cpp
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
71
72
73
74
75
76
77
78
/* ************************************************************************** */
/* */
/* \\ /`/`` */
/* ~\o o_ 0 0\ */
/* / \__) (u ); _ _ */
/* / \/ \/ / \ \/ \/ \ */
/* /( . . ) ( )\ */
/* / \_____/ \_______/ \ */
/* [] [] [[] [[] *. */
/* []] []] [[] [[] */
/* */
/* ****************************************************************** nuo *** */
#include "algorithm"
#include "iostream"
#include "vector"
// DRIVE
long checkII(std::vector<long> v, long n);
bool check(std::vector<long> v);
int main()
{
std::vector<long>::iterator i;
std::vector<long> v;
long n;
while ( std::cin >> n ) v.push_back(n);
i = v.begin() + 25;
while (++i != v.end() - 1)
{
std::vector< long > sub(i - 26, i);
if (!check(sub)) break;
}
std::cout << "Star 1 : " << *(i - 1) << std::endl;
std::cout << "Star 2 : " << checkII(v, *(i - 1)) << std::endl;
}
//
long checkII(std::vector<long> v, long n)
{
std::vector<long>::iterator i, j;
long t;
i = v.begin() - 1;
while (*(++i) < n)
{
t = *i;
j = i;
while (*(++j) < n)
{
t += *j;
if (t == n)
return (*std::min_element(i, j) + *std::max_element(i, j));
if (t > n) break;
}
}
return (-1);
}
bool check(std::vector<long> v)
{
std::vector<long>::iterator i, j;
bool found = false;
i = v.begin() - 1;
while (++i != v.end() - 2)
{
j = i;
while (++j != v.end() - 1)
if ( *(v.end() - 1) == *i + *j) found = true;
}
if (!found) return (false);
return (true);
}