-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxes.c
More file actions
122 lines (88 loc) · 1.91 KB
/
Boxes.c
File metadata and controls
122 lines (88 loc) · 1.91 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
#hackerrank
Problem-
You are transporting some boxes through a tunnel, where each box is a parallelepiped, and is characterized by its length, width
and height.The height of the tunnel 41 feet and the width can be assumed to be infinite. A box can be carried through the
tunnel only if its height is strictly less than the tunnel's height. Find the volume of each box that can be successfully t
ransported to the other end of the tunnel. Note: Boxes cannot be rotated.
Input Format
The first line contains a single integer n, denoting the number of boxes.
lines follow with three integers on each separated by single spaces , and which are length, width and height in feet of the
-th box.
Output Format
For every box from the input which has a height lesser than
feet, print its volume in a separate line.
Sample Input 0
4
5 5 5
1 2 40
10 5 41
7 2 42
Sample Output 0
125
80
*/
#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;
};
typedef struct box box;
int get_volume(box b) {
/**
* Return the volume of the box
*/
return ((b.length)*(b.width)*(b.height));
}
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<MAX_HEIGHT)
{
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;
}
/*
OUTPUT
Input (stdin)
Download
4
5 5 5
1 2 40
10 5 41
7 2 42
Your Output (stdout)
125
80
Expected Output
Download
125
80
*/