-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathboxTunnel.c
54 lines (49 loc) · 957 Bytes
/
boxTunnel.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
52
53
54
/* A Problem from Hackerrank */
#include <stdio.h>
#include <stdlib.h>
#define MAX_HEIGHT 41
struct box
{
/**
* Define three fields of type int: length, width and height
*/
int length;
int width;
int height;
struct box* next;
};
typedef struct box box;
int get_volume(box b) {
/**
* Return the volume of the box
*/
int volume = b.length * b.width * b.height;
return volume;
}
int is_lower_than_max_height(box b) {
/**
* Return 1 if the box's height is lower than MAX_HEIGHT and 0 otherwise
*/
if(b.height < 41) {
b = *b.next;
return 1;
}
else {
return 0;
}
}
int main()
{
int n;
scanf("%d", &n);
box *boxes = malloc(n * sizeof(box));
for (int i = 0; i < n; i++) {
scanf("%d%d%d", &boxes[i].length, &boxes[i].width, &boxes[i].height);
}
for (int i = 0; i < n; i++) {
if (is_lower_than_max_height(boxes[i])) {
printf("%d\n", get_volume(boxes[i]));
}
}
return 0;
}