Connection Status:
Competition Arena > LuckyCounter
SRM 490 · 2010-03-12 · by Chmel_Tolstiy · String Parsing
Class Name: LuckyCounter
Return Type: int
Method Name: countLuckyMoments
Arg Types: (vector<string>)
Problem Statement

Problem Statement

Suppose that we're given a moment of time written as HH:MM, where HH is the hour and MM is the minutes. Let's say that this moment is lucky if it is formatted AB:AB, AA:BB or AB:BA, where both occurrences of A stand for the same digit and both occurrences of B also stand for the same digit. It is allowed for the digits represented by A and B to be the same as well.

You are given a String[] moments, where each element represents a single moment of time. Return how many of these time moments are lucky.

Constraints

  • moments will contain between 1 and 50 elements, inclusive.
  • Each element of moments will be formatted "HH:MM" (quotes for clarity), where HH is between 00 and 23, inclusive, and MM is between 00 and 59, inclusive.
Examples
0)
{"12:21", "11:10"}
Returns: 1

12:21 is lucky, while 11:10 is not.

1)
{"00:00", "00:59", "23:00"}
Returns: 1

Only 00:00 is lucky here (note that it is formatted AB:AB, AA:BB and AB:BA at the same time).

2)
{"12:34"}
Returns: 0
3)
{"12:11", "22:22", "00:01", "03:30", "15:15", "16:00"}
Returns: 3
4)
{"22:33","11:00"}
Returns: 2

Submissions are judged against all 115 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class LuckyCounter with a public method int countLuckyMoments(vector<string> moments) · 115 test cases · 2 s / 256 MB per case

Submitting as anonymous