#K88687. Determining Unreturned Borrowed Books
Determining Unreturned Borrowed Books
Determining Unreturned Borrowed Books
You are given a series of transactions in a library where each transaction is represented as a string. Each transaction is either borrow X
or return X
, where X is the unique identifier of a book.
Your task is to determine which books are still borrowed and have never been returned. The output should be the list of such book IDs sorted in lexicographical order.
In summary, compute the set difference between the borrowed and returned books and output the result in sorted order.
Note: Even if a book is borrowed multiple times, if it has been returned at least once, consider it as completely returned.
inputFormat
The first line contains an integer n, representing the number of transactions.
Each of the next n lines contains a transaction in the format borrow X
or return X
, where X is a string representing the book ID.
outputFormat
Print the sorted list of book IDs that are currently borrowed and have never been returned. If no such books exist, print an empty line.
The book IDs should be separated by a single space.
## sample6
borrow B123
borrow B456
return B123
borrow A789
return B456
borrow A123
A123 A789
</p>