Question Name:Novels

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

struct avi
{
char c[50];
int a;
} s1[20];
int main()
{
int i,k,tem,j;
char temp[50];
scanf("%d",&k);

for(i=0;i<k;i++) {
scanf("%s%d",s1[i].c,&s1[i].a);
}
for(i=0;i<k;i++) {
for(j=i+1;j<k;j++) {
if(s1[i].a<s1[j].a)
{

tem=s1[i].a; strcpy(temp, s1[i].c);

s1[i].a=s1[j].a; strcpy(s1[i].c, s1[j].c);
s1[j].a=tem; strcpy(s1[j].c, temp);

}
}
} if(s1[4].a==s1[5].a){ strcpy(temp, s1[4].c); strcpy(s1[4].c, s1[5].c);
strcpy(s1[5].c, temp); }
printf("Name Year\n");
for(i=0;i<k;i++) {
printf("%s %d\n",s1[i].c,s1[i].a) ;
}
//if(s1[4].a==s1[5].a){
// printf("\nName Year\n%s %d",s1[5].c,s1[5].a);
//}
// else
// {
printf("\nName Year\n%s %d",s1[4].c,s1[4].a);
// }
return 0;
}

Problem Description

There are some set of novels based on the year of Publication, you have to find the book at the position 5.

 

  • Test Case 1

    Input (stdin)

    10
    OOPswithc++ 
    2000
    DatabaseManagementsystems 
    1998
    ComputerArchitecture
    2002
    Compilerdesign 
    2003
    Datastructures 
    2005
    JavaProgramming 
    2009
    CProgramming 
    2007
    Cloudcomputing 
    2006
    Wirelessnetworks
    2010
    Mobilecomputing 
    2014
    

    Expected Output

    Name Year
    Mobilecomputing 2014
    Wirelessnetworks 2010
    JavaProgramming 2009
    CProgramming 2007
    Cloudcomputing 2006
    Datastructures 2005
    Compilerdesign 2003
    ComputerArchitecture 2002
    OOPswithc++ 2000
    DatabaseManagementsystems 1998
    
    Name Year
    Cloudcomputing 2006
  • Test Case 2

    Input (stdin)

    10
    OOPswithc++ 
    2001
    DatabaseManagementsystems 
    1998
    ComputerArchitecture
    2009
    Compilerdesign 
    2003
    Datastructures 
    2015
    JavaProgramming 
    2009
    CProgramming 
    2011
    Cloudcomputing 
    2006
    Wirelessnetworks
    2010
    Mobilecomputing 
    2014
    

    Expected Output

    Name Year
    Datastructures 2015
    Mobilecomputing 2014
    CProgramming 2011
    Wirelessnetworks 2010
    ComputerArchitecture 2009
    JavaProgramming 2009
    Cloudcomputing 2006
    Compilerdesign 2003
    OOPswithc++ 2001
    DatabaseManagementsystems 1998
    
    Name Year
    ComputerArchitecture 2009

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro