-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc1702_spreadsheet.cpp
84 lines (80 loc) · 2.89 KB
/
aoc1702_spreadsheet.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
79
80
81
82
83
84
/* ************************************************************************** */
/* */
/* \\ /`/`` */
/* ~\o o_ 0 0\ */
/* / \__) (u ); _ _ */
/* / \/ \/ / \ \/ \/ \ */
/* /( . . ) ( )\ */
/* / \_____/ \_______/ \ */
/* [] [] [[] [[] *. */
/* []] []] [[] [[] */
/* */
/* ****************************************************************** nuo *** */
#include "iostream"
#include "fstream"
#include "sstream"
#include "vector"
int main()
{
int tt_dif, tt_div, flag, max, min, i, j, k, a, b;
std::vector< std::vector<int> > arr;
std::ifstream file("spreadsheet", std::ios::in);
if (file.good())
{
std::string s;
while (getline(file, s))
{
std::stringstream ss(s);
std::vector<int> tmp;
int n;
while (ss >> n) tmp.push_back(n);
arr.push_back(tmp);
}
}
tt_dif = i = 0;
while (i < (int) arr.size())
{
j = 1;
max = min = arr[i][0];
while (j < (int) arr[i].size())
{
if (max < arr[i][j]) max = arr[i][j];
if (min > arr[i][j]) min = arr[i][j];
j++;
}
i++;
tt_dif += max - min;
}
tt_div = i = 0;
while (i < (int) arr.size())
{
j = 0;
while (j < (int) arr[i].size() - 1)
{
k = j + 1;
flag = 0;
while (k < (int) arr[j].size())
{
a = arr[i][j];
b = arr[i][k++];
if (a > b && !(a % b))
{
tt_div += a / b;
flag++;
break;
}
if (a <= b && !(b % a))
{
tt_div += b / a;
flag++;
break;
}
if (flag) break;
}
j++;
}
i++;
}
std::cout << "Star 1 : " << tt_dif << std::endl;
std::cout << "Star 2 : " << tt_div << std::endl;
}