Gyeol! Hap!
InterviewTime limit1sMemory limit256 MB
Score a Set-like game by checking each called triple against the hap rule and each gyeol against remaining uncalled haps.
- Level
Medium4 of 10
- Topics
- Brute force, Implementation, Array
- Solved
- No attempts yet
Problem

The game Gyeol! Hap! is played with nine pictures chosen from 27 pictures that combine three attributes in every possible way: shape, shape color, and background color. The shapes are {circle, triangle, square}, the shape colors are {yellow, red, blue}, and the background colors are {gray, white, black}. Given the three attributes of the nine pictures, the player must find triples of pictures that form a hap. A hap is a triple of pictures whose three attributes are all the same or all different.

For example, in Example 1 above, the three pictures have the same shape, all different shape colors, and the same background color. All three attributes are therefore all the same or all different, so they form a hap. In Example 2, however, the three pictures have all different background colors and all different shapes, but their shape colors are neither all different nor all the same, so they do not form a hap.
The game Gyeol! Hap! starts with an initial score of 0, and the player can gain points with the following two actions.
- Calling hap: the player calls out the numbers of three distinct pictures thought to form a hap. If the three called pictures form a hap and this combination of pictures has not been called before, the player gains +1 point; otherwise the player gains -1 point.
- Calling gyeol: when the player thinks no uncalled hap remains among the haps that can be made from the nine pictures, the player calls gyeol. If indeed no uncalled hap remains and the player has never gained +3 points by calling gyeol, the player gains +3 points; otherwise the player gains -1 point.
Given the attributes of the nine pictures used in the game and the player's game record, write a program that computes the player's final score.
Input
Nine lines follow the first line. The i-th line (1 ≤ i ≤ 9) gives Si, Ci, Bi, which are the shape, shape color, and background color of picture i.
Si is one of {"CIRCLE", "TRIANGLE", "SQUARE"}, Ci is one of {"YELLOW", "RED", "BLUE"}, and Bi is one of {"GRAY", "WHITE", "BLACK"}. Each attribute is separated by a single space.
The tenth line gives n (1 ≤ n ≤ 100), the number of entries in the player's game record. Each of the next n lines is one of the following two kinds of input.
- H a b c : the player called out the numbers a, b, c of three distinct pictures thought to form a hap. (1 ≤ a, b, c ≤ 9)
- G : the player called gyeol.
Output
Print the player's final score on the first line.