(HackerRank) Write a Modular C Programming code to solve QUEUES – Indian Sports Academy, Number of candidates not selected for Olympics 2022.
Indian Sports Academy conducting selection trials for young candidates who are willing to participate in Olympics 2022. Any candidate between the age group 18 to 35 can participate in the selection process. Indian Sports Academy shortlists based on the height of candidates to be selected for next rounds and only one candidate is selected from each round. Candidates are allowed to enter on first come first serve basis, but only the candidates with a height greater than 185 centimetres will be selected for next round. Given the heights of candidates determine how may candidates are not selected for Olympics 2022.
Input Format
First Line indicates number of candidates N.
Second Line indicates height of candidates. (integer values seperated by a space)
Constraints
0 < N <= 100
Height of candidates is integer values.
Output Format
Number of candidates not selected for Olympics 2022.
Sample Input 0
7
213 200 160 225 185 195 175
Sample Output 0
3
Sample Input 1
2
210 190
Sample Output 1
0
CODE:
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #define SI 100 struct queue { int data[SI],front,rear; }; void enqueue(struct queue *qptr,int num) { if(qptr->rear==SI-1) { printf("Queue Overflow\n"); } else { qptr->rear++; qptr->data[qptr->rear]=num; } } int dequeue(struct queue *qptr) { int num=0; if(qptr->front==qptr->rear) { return num; } else { qptr->front++; num=qptr->data[qptr->front]; return num; } } int main() { struct queue * qptr; struct queue q; qptr=&q; qptr->front=qptr->rear=-1; int num,n,i,sum=0,c,count=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&num); enqueue(qptr,num); } while(qptr->rear!=qptr->front) { c=dequeue(qptr); if(c<=185) { count++; } } printf("%d",count); 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) 7 213 200 160 225 185 195 175 Your Output (stdout) 3 Expected Output 3
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