-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02.c
51 lines (46 loc) · 1016 Bytes
/
02.c
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
/********************************************
*Advent of Code *
*Program Name: Day 2 *
*Programming Language: C *
*Author: José I. Escudero *
*E-mail: [email protected] *
*Date(DD/MM/YYYY): 13/12/2015 *
********************************************/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE* fp;
fp = fopen("02.txt", "r");
unsigned long counter = 0, ribbon = 0;
unsigned int l, w, h, a, b, c, bow, temp;
while(fscanf(fp, "%ux%ux%ux", &l, &w, &h), !feof(fp))
{
a = l*w;
b = w*h;
c = h*l;
counter += 2*a + 2*b + 2*c + (a < b ? (a < c ? a : c) : (b < c ? b : c));
bow = l* w * h;
if(h > w)
{
temp = w;
w = h;
h = temp;
}
if(w > l)
{
temp = l;
l = w;
w = temp;
}
if(l > h)
{
temp = h;
h = l;
l = temp;
}
ribbon += l + l + w + w + bow;
}
fclose(fp);
printf("%lu\n%lu", counter, ribbon);
}