#K68272. Longest Consecutive Book Sequence
Longest Consecutive Book Sequence
Longest Consecutive Book Sequence
You are given a sequence of books. Each book is represented by its title and a list of authors. The books are given in a specific order, and a book is considered "consecutive" with the next book if they share at least one common author.
Your task is to determine the length of the longest consecutive sequence of books where every adjacent pair of books in the sequence has at least one author in common.
The input is provided via standard input (stdin) and the result must be printed to standard output (stdout).
Note: The title of a book will be enclosed in double quotes, and the list of authors will be provided as a comma-separated string immediately following the title with a space between them.
Example:
4 "The Great Gatsby" F.ScottFitzgerald "To Kill a Mockingbird" HarperLee "Go Set a Watchman" HarperLee "The Catcher in the Rye" J.D.Salinger
For the above input, the longest consecutive sequence is 2 because "To Kill a Mockingbird" and "Go Set a Watchman" share a common author.
inputFormat
The first line contains an integer n, representing the number of books.
Each of the following n lines contains a book description. The description is in the following format:
"Book Title" Author1,Author2,...
The book title is enclosed in double quotes. After the quotes, there is a space followed by a comma-separated list of author names (without extra spaces in between, though spaces may appear after the commas).
outputFormat
Output a single integer which denotes the length of the longest consecutive sequence of books where each consecutive pair of books share at least one common author.
## sample4
"The Great Gatsby" F.ScottFitzgerald
"To Kill a Mockingbird" HarperLee
"Go Set a Watchman" HarperLee
"The Catcher in the Rye" J.D.Salinger
2