During a soccer match, the referee can warn players by showing them red or yellow cards. When a player is shown a red card, he is sent off the field immediately. The first time a player is shown a yellow card, it serves as a warning. The second time he is shown a yellow card in the same match, he is immediately shown a red card as well, and sent off the field. When players are sent off the field, they are out for the remainder of the match. During the last World Cup, a referee forgot that one of the players was already shown a yellow card, and did not send him off after the second one. You are to write a program to prevent such errors. You will be given a vector info, the i-th element of which represents the i-th card shown during the match. Each element of info will be formatted as "C NN SURNAME" (quotes for clarity only). C is a character 'Y' or 'R', representing a yellow or red card, respectively. NN is a two-digit number representing the minute when the card was shown. SURNAME contains between 2 and 20 uppercase letters and represents the surname of the player who was shown the card. For the purposes of this problem, we assume that surnames are unique for all players. If you find that the referee made at least one error during the match (i.e., he showed a second yellow card to one player but didn't show him a red card at the same minute), return the earliest minute when this happened. If the referee didn't make any errors, return -1. Please note that the referee may occasionally show more than two yellow cards to the same player during a single minute, and this is legal as long as he also shows the red card to that player later in the same minute (see example 6). Definition
Class: RedCard Method: firstError Parameters: vector Returns: int Method signature: int firstError(vector info) (be sure your method is public)
Constraints - All elements of info will be in chronological order. In other words, the time represented by the i-th element of info will be greater than or equal to the time represented by the (i-1)-th element. - If a player is shown a red card, no later elements of info will contain that player. - info will contain between 0 and 50 elements, inclusive. - Each element of info will contain between 7 and 25 characters, inclusive. - Each element of info will be formatted as "C NN SURNAME". - In each element of info C will be either 'Y' or 'R'. - In each element of info NN will be a two-digit number between 00 and 90, inclusive. - In each element of info SURNAME will contain between 2 and 20 uppercase letters ('A' - 'Z'), inclusive. Examples 0)
{"Y 10 JOHNS", "Y 10 SMITH", "Y 20 JOHNS", "Y 20 SMITH", "R 20 SMITH", "R 20 JOHNS"} Returns: -1 Both red cards are shown at the same minute as the second yellow cards, so the referee didn't make any error here. 3)
{"Y 10 JOHNS", "Y 15 JOHNS", "Y 70 JOHNS", "R 70 JOHNS"} Returns: 15
4)
{"Y 10 SMITH", "Y 13 WILLIAMS", "Y 70 SMITH", "Y 70 JOHNS", "R 70 SMITH", "Y 71 JOHNS", "R 71 JOHNS", "R 90 WILLIAMS"} Returns: -1
5)
{ "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 02 JOHNS" } Returns: 1 Both Johns and the referee were really active from the very beginning of the game. 6)
{ "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "Y 01 JOHNS", "R 01 JOHNS" } Returns: -1