← 返回 amazon 的题目列表Character Occurrence in Books
类型:online_judge
amazon
Given a List of Book objects, you need to implement an API that, given a Character name, returns the number of times it appears in all books. The specific requirements are as follows:
Two known interfaces are provided:
List<Line> BookParser.getLines(Book book): Given a book, returns all the lines in the book.
List<Character> EntityParser.getCharacters(Line line): Given a line, returns all the characters that appear in that line.
Please implement the method Map<String, Map<String, Integer>> getCharacterOccurrences(List<Book> books), which takes a list of books as input and outputs the number of appearances of each character in each book.
Example Input/Output:
Input: List of Book objects.
Output: `
Example
Input
List of Book objects with one book, and book contains three characters
Book(name="Book A") with Lines: [Line1: ['Char1', 'Char2'], Line2: ['Char1', 'Char3']]
Character queried: 'Char1'
Expected Output: {'Char1': {'Book A': 2}}