#K41742. Song Genre Classification
Song Genre Classification
Song Genre Classification
You are given the lyrics of a song as a single line of text. Your task is to predict the genre of the song based on predefined word frequency dictionaries for three genres. For each genre, the word frequencies are defined as follows:
- Genre 1: {
love: 10
,baby: 5
,dance: 3
} - Genre 2: {
rock: 10
,guitar: 4
,band: 7
} - Genre 3: {
jazz: 8
,saxophone: 5
,smooth: 2
}
For a given lyric, compute the score for each genre using the formula below:
\[ score = \sum_{w \in \text{words}} (\text{frequency}(w) \times \text{count}(w)) \]
where \(\text{frequency}(w)\) is the value of word \(w\) in the genre's dictionary and \(\text{count}(w)\) is the number of occurrences of \(w\) in the input lyric. Output the genre id (1, 2, or 3) that has the highest score. In case of ties, choose the genre with the smallest id.
inputFormat
The input consists of a single line containing the song lyrics. The lyrics are provided as space-separated words, all in lowercase.
outputFormat
Output a single integer representing the predicted genre id (either 1, 2, or 3).
## samplebaby love baby dance
1