Boxes through a Tunnel || Hacker Rank

 Question 23 || Hacker Rank

Boxes through a Tunnel || Hacker Rank

Boxes through a Tunnel



You are shipping a few boxes through a passage, where each case is a parallelepiped, and is described by its length, width and level.

 

The level of the passage 41 feet and the width can be thought to be endless. A container can be helped through the passage provided that its level is completely not exactly the passage's level. Find the volume of each container that can be effectively moved to the opposite finish of the passage. Note: Boxes can't be pivoted.

 

Input Configuration

 

The main line contains a solitary whole number n, meaning the quantity of boxes.

 n lines follow with three whole numbers on each isolated by single spaces - lengthi, widthiand heighti which are length, width and level in feet of the i-th box.

 

Requirements

Boxes through a Tunnel



Yield Arrangement

For each container from the info which has a level lesser than 41 feet, print its volume in a different line.

 

Test Information 0

 

4

5 5 5

1 2 40

10 5 41

7 2 42

Test Result 0

 

125

80

Clarification 0

 

The primary box is extremely low, just 5 feet tall, so it can go through the passage and its volume is 5 x 5 x 5 = 125.

 

The subsequent box is adequately low, its volume is 1 x 2 x 40 = 80.

 

The third box is precisely 41 feet tall, so it can't pass. The equivalent can be said about the fourth box.



Source Code:

#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 b.length * b.width * b.height;
}

int is_lower_than_max_height(box b) {
   
    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:

Boxes through a Tunnel


Post a Comment

0 Comments