C Programming – HackerRank Solution | Wynk online music player |

(HackerRank) Write a Modular C Programming code to solve Wynk online music player, NOTE: Each song details are: song name, singer name, duration (mm.ss) and year.

Sham uses Wynk online music player as he is fond of listening to music. However, he also wants to develop an offline music player where he can add the songs and delete the songs from the player. He wants to have a music player to: Display all the songs which are sung by a particular singer. Delete the particular song by song name.

NOTE: Each song details are: song name, singer name, duration (mm.ss) and year.

Input Format

First line indicates N – number of songs.

Next N lines are details of songs.

After inputting songs details, input is Singer name.

Last line is song name input to delete the song.

Constraints

N should be positive.

Output Format

Display all the songs.

Display songs of particular singer.

Display deleted song.

Sample Input 0

4
maralimanasagide raghu 3.02 2021
sariyaagi armaan 4.21 2016
kannada raghu 5.20 2010
usire rajesh 5.38 2001
raghu
usire

Sample Output 0

maralimanasagide raghu 3.02 2021
sariyaagi armaan 4.21 2016
kannada raghu 5.20 2010
usire rajesh 5.38 2001

maralimanasagide raghu 3.02 2021
kannada raghu 5.20 2010

Deleted usire rajesh 5.38 2001

Sample Input 1

5
ninnaraja armaan 4.38 2019
sariyaagi armaan 4.21 2016
kannada raghu 5.20 2010
manase sonu 6.48 2014
nannavale sonu 6.48 2014
shreya
kanasu

Sample Output 1

ninnaraja armaan 4.38 2019
sariyaagi armaan 4.21 2016
kannada raghu 5.20 2010
manase sonu 6.48 2014
nannavale sonu 6.48 2014

No songs of shreya to display

No song kanasu to delete

Sample Input 2

4
sariyaagi armaan 4.21 2016
kannada raghu 5.20 2010
manase sonu 6.48 2014
nannavale sonu 6.48 2014
sonu
kanasu

Sample Output 2

sariyaagi armaan 4.21 2016
kannada raghu 5.20 2010
manase sonu 6.48 2014
nannavale sonu 6.48 2014

manase sonu 6.48 2014
nannavale sonu 6.48 2014

No song kanasu to delete

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
{
    char song[20];
    char singer[20];
    float a;
    int b;
    struct node *rightlink;
    struct node *leftlink;
};
typedef struct node *NODE;
NODE insert_end(NODE head);
void display(NODE head);
void songs_of_singer(NODE head,char *a);
void delete_song(NODE head,char *ch);
NODE create_node();
int main() {
    int n;
    NODE head=NULL;
    scanf("%d",&n);
    for(int i=0;i<n;i++) { 
head=insert_end(head); }
 char singer[20],delete[20];
 scanf("%s",singer); 
scanf("%s",delete); 
display(head); 
songs_of_singer(head,singer);
 delete_song(head,delete);
 return 0; } 
NODE create_node() { 
NODE newnode; 
newnode=malloc(sizeof(struct node));
 scanf("%s %s %f%d",newnode->song,newnode->singer,&newnode->a,&newnode->b);
    newnode->rightlink=NULL;
    newnode->leftlink=NULL;
    return newnode;
}
NODE insert_end(NODE head)
{
    NODE newnode;
    newnode=create_node();
    NODE cur=head;
    if(head==NULL)
    {
        head=newnode;
    }
    else{
    while(cur->rightlink!=NULL)
    {
        cur=cur->rightlink;
    }
    cur->rightlink=newnode;
    newnode->leftlink=cur;
    }
    return head;
}
void display(NODE head)
{
    NODE newnode=head;
    while(newnode!=NULL)
    {
        printf("%s %s %0.2f %d\n",newnode->song,newnode->singer,newnode->a,newnode->b);
        newnode=newnode->rightlink;
    }
    printf("\n");
}
void songs_of_singer(NODE head,char *singer)
{
    NODE cur=head;
    int status=0;
    while(cur!=NULL)
    {
        if(strcmp(cur->singer,singer)==0)
        {printf("%s %s %0.2f %d\n",cur->song,cur->singer,cur->a,cur->b);status=1;}
        cur=cur->rightlink;
    }
    if(status==0)
        printf("No songs of %s to display\n\n",singer);
    else
        printf("\n");
}
void delete_song(NODE head,char *song)
{
    NODE cur=head;
    int status=0;
    while(cur!=NULL)
    {
        if(strcmp(cur->song,song)==0)
        {
            printf("Deleted %s %s %0.2f %d\n",cur->song,cur->singer,cur->a,cur->b);
            status=1;
        }
        cur=cur->rightlink;
    }
    if(status==0)
        printf("No song %s to delete",song);
}

OUTPUT

Congratulations, you passed the sample test case.

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

Input (stdin)

4
maralimanasagide raghu 3.02 2021
sariyaagi armaan 4.21 2016
kannada raghu 5.20 2010
usire rajesh 5.38 2001
raghu
usire
Your Output (stdout)

maralimanasagide raghu 3.02 2021
sariyaagi armaan 4.21 2016
kannada raghu 5.20 2010
usire rajesh 5.38 2001

maralimanasagide raghu 3.02 2021
kannada raghu 5.20 2010

Deleted usire rajesh 5.38 2001
Expected Output

maralimanasagide raghu 3.02 2021
sariyaagi armaan 4.21 2016
kannada raghu 5.20 2010
usire rajesh 5.38 2001

maralimanasagide raghu 3.02 2021
kannada raghu 5.20 2010

Deleted usire rajesh 5.38 2001

 

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