C Programming – HackerRank Solution | Shirdi Sai Temple |

(HackerRank) Write a Modular C Programming code to solve Shirdi Sai Temple, Shirdi Sai Temple is one among the most visited places for worship in India.

Shirdi Sai Temple is one among the most visited places for worship in India.

The number of devotees visiting the temple each day is very high, the head of the temple has to monitor the devotees and are allowed with a specific preference to worship each day.

Today is another crowdie day, head of the Shirdi Sai temple thought to apply certain protocol to manage the devotees.

First, he allowed all the devotees to stand in a line in first come last served basis.

Then he identified the devotee whose age is most among all and allowed him/her to worship.

Please help the head of the temple to manage the devotees.

Input Format

First Line – N – indicates number of devotees.

Second Line – age of the devotees.

Constraints

N should be positive value between 1 to 100.

Age should be positive value 1 to 200.

Output Format

First line – Age of devotee allowed for worship.

Second line – Age of remaining devotees.

Sample Input 0

5
50 25 34 54 12

Sample Output 0

Allowed for worship: 54
Remaining devotees: 12 34 25 50

Sample Input 1

1
50

Sample Output 1

Allowed for worship: 50
No devotees to worship.

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 data;
  struct node *link;
};
typedef struct node *NODE;
void display(NODE head)
{
    NODE cur=head;
    if(head==NULL)
    {
        printf("No devotees to worship.");
    }
    else{
    printf("Remaining devotees: ");
    while(cur!=NULL)
    {
        printf("%d ",cur->data);
        cur=cur->link;
    }
    }
}
NODE insert_front(NODE head)
{
    NODE newnode=malloc(sizeof(struct node));
    scanf("%d",&newnode->data);
    newnode->link=head;
    head=newnode;
    return head;
}
NODE search_and_delete_highest(NODE head)
{
    NODE cur=head;
    NODE max=head;
    NODE prev=NULL;
    NODE PREV=NULL;
    while(cur!=NULL)
    {
        if(max->datadata)
        {
            PREV=prev;
            max=cur;
        }
        prev=cur;
        cur=cur->link;
    }
    if(max==head)
        head=max->link;
    else
        PREV->link=max->link;
    printf("Allowed for worship: %d\n",max->data);
    free(max); 
    return head;
}
int main() {
    NODE head=NULL;
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        head=insert_front(head);
    }
    head=search_and_delete_highest(head);
    display(head);
    return 0;
}

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
50 25 34 54 12
Your Output (stdout)

Allowed for worship: 54
Remaining devotees: 12 34 25 50 
Expected Output

Allowed for worship: 54
Remaining devotees: 12 34 25 50

 

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 !!!