SMS Poll
Time limit1sMemory limit128 MB
Normalize phone formats to identify each sender, keep only the earliest valid vote per sender, and print truncated percentages and participant count.
- Level
Medium5 of 10
- Topics
- String, Hash map, Implementation
- Solved
- No attempts yet
Problem
The TV show "90%" runs a live SMS poll every week. A poll is one question plus choices numbered 1 through . Viewers vote by texting a number between 1 and to the show's phone number, and the tally appears on screen during the broadcast.
Parliament grew suspicious of the figures announced on last week's broadcast and appointed a committee to look into them. The committee obtained the full list of messages sent to the final broadcast and now wants to process the data. The poll under investigation has four choices.
There are far too many messages to count by hand, so the committee asked for a program that extracts the tally from the raw data. The data is a list of phone:content pairs, where phone is the sender's phone number and content is the message body. Compute the percentage of votes for each choice. The following rules apply.
- In its most general form a phone number looks like "A B C", where A is the country code, B is the area code, and C is the local number. In
+98 (21) 6616-6645the country code is 98, the area code is 21, and the local number is 6616-6645. None of A, B, C starts with the digit 0. - The country code is optional, and when it is written it is always preceded by a
+sign. If it is missing, it is 98. The country code has at most 3 digits. - If the country code is written, the area code must be written too. If the country code is omitted, the area code is optional. When the area code is written, it is either preceded by a 0 digit or surrounded by a pair of parentheses, as in
02166166600and(21)66166600. If the area code is missing, it is 21. The area code has at most 3 digits. - Local numbers vary in length from 3 to 8 digits.
6616and66166600are examples. - The same number may appear in several formats.
09128122190,+98(912)812-2190and0912-812-2190are all the same number. The formatting rules are:- The area code may be surrounded by a pair of parentheses.
- A dash (
-) may sit between any two digits of the local number, or between two of the three parts (country code, area code, local number). A dash and a parenthesis never sit next to each other.
- Every phone number in the raw data is valid and follows the rules above exactly.
- The complete form of a number fills in the omitted country code and area code, then joins the digits of the three parts. The complete form of
+98 (21) 6616is98216616. Two messages with equal complete forms came from the same sender. - Every phone number in the world has a single complete form. For example
(218)4460and(21)84460cannot both exist as different numbers, because both have the complete form982184460. - The only valid message content is a single digit from 1 to 4. Anything else, such as letters or a
+sign, makes the message invalid, and an invalid message is discarded. - A sender may have texted several times from one number. In that case only the earliest valid message counts and the rest are discarded.
- Discarded messages count toward neither the vote total nor the percentages.
Input
The input holds several test cases. The first line of a test case has the number of messages in the list, (). Each of the next lines holds a pair a:b, where is a phone number and is the message content. A phone number never contains :, so the first : on a line ends the phone number and everything after it is the content. The content is at most 30 characters long, and each character is a letter, a digit, or one of :, +, -, (, ). The input ends with a line holding a single 0, which is not processed. The input has no space characters.
Output
Print five lines for each test case.
On the th of the first four lines, print the percentage of votes for choice truncated to an integer, followed by %. If is the number of votes for choice and is the number of counted votes, the value to print is . When , print 0% on all four lines.
On the fifth line, print the number of participants in the form Participants:x. Here is the number of distinct phone numbers appearing in the list, counting numbers that sent no valid message.