Guess the Song from the Intro
Time limit1sMemory limit1024 MB
Given stored songs with their first seven notes, for each query of three notes, print the unique song title starting with those notes, ? if several match, or ! if none.
- Level
Easy2 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
Yunsu and Jeonghwan are going to play a game called Guess the Song from the Intro. In this game, a player hears the intro of a song and tries to name its title first. The player who names it earns a point, and the player with more points at the end wins.
Yunsu has perfect pitch and can name any song after hearing only its first four notes. So Jeonghwan wants to build a program that identifies songs from only their first three notes, so that he can beat Yunsu. He first built data of the song titles and note names he knows, and then started implementing the program. For example, the following is part of the score of TwinkleStar.
``
Ignoring rhythm, the score above is written as the note names CCGGAAG.
To beat Yunsu, the program must be able to print the title TwinkleStar from the first three notes CCG alone. Unlike Yunsu, who knows every song in the world, Jeonghwan knows the notes of only songs. So he will store the information of those songs in the program. If several stored songs begin with the input first three notes so that the song cannot be identified, print ?. If no stored song matches the input first three notes, print !.
Help Jeonghwan finish a program that identifies, from only the first three notes, the songs whose notes he knows. This program is case-sensitive.
Input
The first line contains two integers and , separated by a space: the number of songs whose notes Jeonghwan knows, and the number of songs he will try to name.
From the second line, each of the next lines contains the title length , the title made of English letters, and the seven note names that first appear in that song, separated by spaces.
Each of the next lines contains the three note names of a song Jeonghwan will try to name, separated by spaces.
Each note name is one of C, D, E, F, G, A, B. No title is given more than once.
Output
For each song Jeonghwan tries to name, print one line: the title if exactly one stored song has the same first three notes, ? if two or more do, or ! if none do.
Constraints
- All numbers in the input are integers.