(HackerRank) Write a Modular C Programming code to solve Indian Sports Academy, Indian Sports Academy conducting selection trials for young candidates who are willing to participate in 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 a first come first serve basis, but only the candidates with a height greater than 185 centimeters 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> struct node{ int height; struct node *link; }; typedef struct node *NODE; NODE insert_end(NODE head); NODE qualified(NODE head); int main() { NODE head=NULL; int n; scanf("%d",&n); if(n<0 && n>=100) exit(0); for(int i=0;i<n;i++) { head=insert_end(head); } head=qualified(head); return 0; } NODE insert_end(NODE head) { NODE newnode=malloc(sizeof(struct node)); scanf("%d",&newnode->height); NODE cur=head; if(head==NULL) { head=newnode; } else{ while(cur->link!=NULL) { cur=cur->link; } cur->link=newnode; } newnode->link=NULL; return head; } NODE qualified(NODE head) { NODE cur=head,prev=NULL; int count=0; while(cur!=NULL) { if(cur->height<=185) { if(cur==head) { head=cur->link; free(cur); cur=head; } else{ prev->link=cur->link; free(cur); cur=prev->link; } count++; } else{ prev=cur; cur=cur->link; } } printf("%d",count); return head; }
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