Problem 105: Stop the Spungos
(U.M. ACM Runoffs 2001, problem 5)
Description
There are a large number of couterfeit tickets for the 2001
super bowl on the market. The organisers of the event will tell
you their methods for detecting valid tickets if you'll automate
the process for them.
Each ticket contains three pieces of information: The name of one
of the teams, the name of the other team, and a serial number.
- Team names always have at least 3 and no more than 30 letters
in them.
- Team names may also include spaces, digits, and punctuation,
but these characters do not count as letters.
- Team names never include a question mark ? or a wiggle
~ character.
- There is no team called the "Spungos".
- Case is irrelevant in team names, so "RATS", "rats", and "Rats"
all refer to the same team.
- All characters in a team name are relevant, so the "LA Gits"
(with a space) are a different team from the "Lagits" (no space).
- The serial number is always an integer consisting of exactly
30 digits. These 30 digits may include a number of leading zeros.
- The serial number is always exactly divisible by 13.
- The information on the ticket always consists of a team name,
immediately followed by a ~, immediately followed by
another team name, immediately followed by another ~,
immediately followed by the serial number, and nothing else.
- There will always be two different teams in the game: the
Rats will never play agains the Rats in the super bowl.
Any ticket that conforms to all of those rules is considered
valid. Any ticket that breaks any of those rules is rejected.
Input Format
There will be a number of lines of input, each line will contains
exactly the information from one ticket. The last line in the
input will contain just the three character sequence "END", which
should not be processed as a ticket.
Output Format
For each input ticket, print a single line, stating "Ticket number
NNN: good" if the ticket is accepted, or "Ticket number NNN: BAD!!!"
if the ticket is rejected. NNN should be replaced by the number of the
ticket in the input sequence (starting with 1), not the ticket's
serial number.
Limits
No line of input will contain more than 1000 characters.
Sample Input
Rams~Broncos~000000000000000000000000000013
L.A. Bastards~Oakland Browns~000000000000000000000000002639
49ers~Mets~132613261326391326393939132652
Jets~Sharks~001313131326262626131313262613
Cowboys~Spungos~001313131326262626131313262613
Dallas Cowboys~Boston Spungos~001313131326262626131313262613
Atlanta Rednecks~Dallas Gayboys~001313131326262626131313262614
Bubs Team~Knicks~1313131313131313131313131313
Team A~Team B~596349123761250925101011010178
Cowboys~Cowboys~001313131326262626131313262613
Team A~Team B~596349123761250925101011010178~Drink Coke!
END
Sample Output
Ticket number 1: good
Ticket number 2: good
Ticket number 3: good
Ticket number 4: good
Ticket number 5: BAD!!!
Ticket number 6: good
Ticket number 7: BAD!!!
Ticket number 8: BAD!!!
Ticket number 9: good
Ticket number 10: BAD!!!
Ticket number 11: BAD!!!
Explanation of Sample
Ticket 5: "Spungos" is not a proper team.
Ticket 6: "Boston Spungos" is OK, only the "Spungos" are forbidden.
Ticket 7: Serial number not divisible by 13.
Ticket 8: Serial number not 30 digits.
Ticket 9: A big number that's divisible by 13. That will make testing easier for you.
Ticket 10: The Cowboys are playing with themselves.
Ticket 11: Not just the three components.
End of Problem