Skip to main content

Nptel week 5 data structure and algorithm answer



Write a Python program to read the data as described above and print out details about books that have been checked out. Each line should describe to one currently issued book in the following format:

Due Date~Full Name~Accession Number~Title
Your output should be sorted in increasing order of due date. For books due on the same date, sort in increasing order of full name. If the due date and full name are both the same, sort based on the accession number, and, finally, the title of the book.

Here are a sample input and its corresponding output.

Sample Input

Books
APM-001~Advanced Potion-Making
GWG-001~Gadding With Ghouls
APM-002~Advanced Potion-Making
DMT-001~Defensive Magical Theory
DMT-003~Defensive Magical Theory
GWG-002~Gadding With Ghouls
DMT-002~Defensive Magical Theory
Borrowers
SLY2301~Hannah Abbott
SLY2302~Euan Abercrombie
SLY2303~Stewart Ackerley
SLY2304~Bertram Aubrey
SLY2305~Avery
SLY2306~Malcolm Baddock
SLY2307~Marcus Belby
SLY2308~Katie Bell
SLY2309~Sirius Orion Black
Checkouts
SLY2304~DMT-002~2019-03-27
SLY2301~GWG-001~2019-03-27
SLY2308~APM-002~2019-03-14
SLY2303~DMT-001~2019-04-03
SLY2301~GWG-002~2019-04-03
EndOfInput
Sample Output

2019-03-14~Katie Bell~APM-002~Advanced Potion-Making
2019-03-27~Bertram Aubrey~DMT-002~Defensive Magical Theory
2019-03-27~Hannah Abbott~GWG-001~Gadding With Ghouls
2019-04-03~Hannah Abbott~GWG-002~Gadding With Ghouls
2019-04-03~Stewart Ackerley~DMT-001~Defensive Magical Theory









def borrowers_input(b):
   x=input()
   while x!='Checkouts':
        x=x.split('~')
        b.append(x)
        x=input()

def checkouts_input(c):
    x=input()
    while x!='EndOfInput':
        x=x.split('~')
        c.append(x)
        x=input()

def output():
    global books,borrower,checkout
    date=[]
    uname=[]
    name=[]
    Anum=[]
    title=[]
    for i in range(0,len(checkout)):
        date.append(checkout[i][2])

    for i in range(0,len(checkout)):
        uname.append(checkout[i][0])

    for i in range(0,len(uname)):
        for j in range(0,len(borrower)):
            if(uname[i] == borrower[j][0]):
                name.append(borrower[j][1])

    for i in range(0,len(checkout)):
        Anum.append(checkout[i][1])

    for i in range(0,len(Anum)):
        for j in range(0,len(books)):
            if(Anum[i] == books[j][0]):
                title.append(books[j][1])

    final=[]
    for i in range(0,len(checkout)):
        final.append(date[i]+'~'+name[i]+'~'+Anum[i]+'~'+title[i])
    final.sort()
    for i in range(0,len(final)):
        print(final[i])


books=[]
borrower=[]
checkout=[]
x=input()
x=input()
while x!='Borrowers':
    x=x.split('~')
    books.append(x)
    x=input()
borrowers_input(borrower)
borrower.sort()
checkouts_input(checkout)
output()

Comments

Popular posts from this blog

Dragon Ball super Broly

                                                     Dragon ball super takes place after the tournament of power and the story revolve around how Broly and his father where exile from the empire by King Vegeta father and were forced to live on a planet far away from they actual home. Vegeta father was very jealous of the fact that Broly was way more powerful than his son and because of this, he was abandoned to a faraway planet where he would not be able to come back. Frieza wanted the dragon ball so that he would grow in height by up to 5cm. Broly and his father were found by the Frieza force and were taken to earth so that they could fight Vegeta and Goku.                 This turned to the worst as Broly had gained tremendous power and after each move was becoming stronger and...

SEO vs SEM

SEO (Search Engine Optimization) and SEM (Search Engine Marketing) are valuable, powerful business tools seem to be similar as both are geared towards generating traffic to the website, but when we look the terms deeply these are absolutely different traffic generation method. Search optimization is an essential marketing strategy for brands trying to attract attention, drive website traffic, and grow their business. But search optimization can be a difficult strategy to manage if you don’t know how to compare SEM vs. SEO. The tactics may sound the same, but they are two very different approaches to search optimization. If you use the terms SEM and SEO interchangeably and don’t know the differences between the two, you won’t be able to communicate a clear and effective strategy for improving your visibility in search. What is SEO and SEM SEO or Search Engine Optimisation is the process of optimising a website to rank prominently on the organic search results.SEM or Sear...

Mars orbiter mission

The Mars mission was the most ambitious mission that was done by the ISRO and the chance of succeeding the mission was less than 10 percent in total. The mission was designed to operate in mars for up to 2 years but the mission is still sending scientific data that can be used by the scientist to study the composition of the martian atmosphere. The mars orbiter mission was launched in 2013 and it reached the red planet by 2014 . It had traveled 450 million km to the red planet and it reached the red planet about the week after the NASA mission to the moon maven. This mission was very hard as the people at ISRO didn't have prior experience to do an interplanetary mission to any other planet at all.And this was a mission which was never undertaken by the ISRO scientists. The MOM orbiter included a high gain antenna to send the messages to the earth and the propellant tank had enough fuel for doing a 2-year mission to Mars as it took 1 year for it to reach mars . The Mars...