C Programming – HackerRank Solution | Baggage Carousel |

(HackerRank) Write a Modular C Programming code to solve Baggage Carousel, Note: Luggage is considered Heavyweight if the weight is more than 30kg. Each luggage contains Luggage_ID, Owner name, source, destination and weight.

A baggage carousel is a device, generally, at an airport, that delivers checked luggage to the passengers at the baggage reclaim area at their final destination. Bharath is a developer who wants to develop software to distinguish the heavyweight and lightweight luggage to avoid the crowd at one carousel and also wants to know the least weighted luggage. Please help Bharath to solve the problem by using the problem-solving framework.

Note: Luggage is considered Heavyweight if the weight is more than 30kg. Each luggage contains Luggage_ID, Owner name, source, destination and weight.

Input Format

The first line indicates the total number of luggage.

The next line contains the luggage details.

Constraints

5<=weight<=100

Output Format

The first few lines print the lightweight luggage.

The next few lines print the heavyweight luggage.

The last line displays the least weighted luggage.

Sample Input 0

5
123 Nandish Hubli Bengaluru 22
130 Shivani Ranchi Bengaluru 35
136 Ramesh Gulbarga Bengaluru 32
150 Laxmi Hubli Bengaluru 20
176 Ramesh Gulbarga Bengaluru 28

Sample Output 0

123 Nandish Hubli Bengaluru 22
150 Laxmi Hubli Bengaluru 20
176 Ramesh Gulbarga Bengaluru 28

130 Shivani Ranchi Bengaluru 35
136 Ramesh Gulbarga Bengaluru 32

150 Laxmi Hubli Bengaluru 20

Sample Input 1

4
13 Ramesh London Bengaluru 55
105 Aditya Ranchi Australia 15
136 Wilson Hubli Bengaluru 23
670 Laxmi Hubli Bengaluru 27

Sample Output 1

105 Aditya Ranchi Australia 15
136 Wilson Hubli Bengaluru 23
670 Laxmi Hubli Bengaluru 27

13 Ramesh London Bengaluru 55

105 Aditya Ranchi Australia 15

Refer : C Programming HackerRank all solutions for Loops | Arrays | strings | Data Structures | Linked lists | Stacks | Queues | Binary Trees

 

CODE:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

struct node 
{
    int weight;
    int number;
    char a[20],b[20],c[20];
    struct node *link;
};
typedef struct node *NODE;
void display_lightweight(NODE head);
void display_heavyweight(NODE head);
void display_min(NODE head);
NODE insert_end(NODE head)
{
    NODE cur=head;
    NODE newnode=malloc(sizeof(struct node));
    scanf("%d %s %s %s %d",&newnode->number,newnode->a,newnode->b,newnode->c,&newnode->weight);
   // printf("%d %s %s %s %d\n",newnode->number,newnode->a,newnode->b,newnode->c,newnode->weight);
    if(head==NULL)
    {
        head=newnode;
    }
    else{
        while(cur->link!=NULL)
            cur=cur->link;
        cur->link=newnode;
    }
    newnode->link=NULL;
    return head;
}
int main() {
    int n;
    scanf("%d",&n);
    NODE head=NULL;
    for(int i=0;i<n;i++) { head=insert_end(head); } display_lightweight(head); display_heavyweight(head); display_min(head); return 0; } void display_lightweight(NODE head) { NODE newnode=head; while(newnode!=NULL) { if(newnode->weight<30) printf("%d %s %s %s %d\n",newnode->number,newnode->a,newnode->b,newnode->c,newnode->weight);
        newnode=newnode->link;
    }
      printf("\n");
}
void display_heavyweight(NODE head)
{
    NODE cur=head;
    while(cur!=NULL)
    {
        if(cur->weight>=30)
            printf("%d %s %s %s %d\n",cur->number,cur->a,cur->b,cur->c,cur->weight);
        cur=cur->link;
    } 
      printf("\n");
}
void display_min(NODE head)
{
    NODE min=head;
    NODE cur=head;
    while(cur!=NULL)
    {
        if(min->weight>cur->weight)
            min=cur;
        cur=cur->link;
    }
    printf("%d %s %s %s %d\n",min->number,min->a,min->b,min->c,min->weight);
}

OUTPUT

Congratulations, you passed the sample test case.

Click the Submit Code button to run your code against all the test cases.

Input (stdin)

5
123 Nandish Hubli Bengaluru 22
130 Shivani Ranchi Bengaluru 35
136 Ramesh Gulbarga Bengaluru 32
150 Laxmi Hubli Bengaluru 20
176 Ramesh Gulbarga Bengaluru 28
Your Output (stdout)

123 Nandish Hubli Bengaluru 22
150 Laxmi Hubli Bengaluru 20
176 Ramesh Gulbarga Bengaluru 28

130 Shivani Ranchi Bengaluru 35
136 Ramesh Gulbarga Bengaluru 32

150 Laxmi Hubli Bengaluru 20
Expected Output

123 Nandish Hubli Bengaluru 22
150 Laxmi Hubli Bengaluru 20
176 Ramesh Gulbarga Bengaluru 28

130 Shivani Ranchi Bengaluru 35
136 Ramesh Gulbarga Bengaluru 32

150 Laxmi Hubli Bengaluru 20

 

Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, Stacks, Queues, Binary Trees, MISC, Solved model question papers & Hacker Rank all solutions on the below page:

Top 100+ C Programming codes – KLE Technological University

Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

Welcome to FactsPrime

Sorry, We have detected that you have activated Ad-Blocker. Please Consider supporting us by disabling your Ad Blocker, It helps us in maintaining this website. To View the content, Please disable adblocker and refresh the page.

Thank You !!!