Connection Status:
Competition Arena > Mirror
SRM 104 · 2002-07-11 · by leelin
Class Name: Mirror
Return Type: String
Method Name: mirror
Arg Types: (string)
Problem Statement

Problem Statement

Suppose it is 4:30. The hour hand of a clock would be halfway between 4 and 5. The image of the clock in a mirror would cause the hour hand to reside in the region between 7 and 8 (by perception only, if you couldn't see the numbers). The minute hand is pointed directly down, so its image in the mirror is in the same place as it is not in the mirror. Therefore, in a mirror, the time would appear to be 7:30.

Write a class Mirror that contains a method mirror, which takes as argument a String representation of a clock and returns the observed time if the clock were seen in a mirror.

Assume that it is a 12 hour clock and that it has an hour hand and a minute hand that move continuously at their respective speeds. Thus, when it is 12:00, both hands point straight up.

Notes

  • The return format is expected to be the same as the input, so that mirror is its own inverse. That is, given a valid input s, then mirror (mirror (s)) is the same as s.

Constraints

  • time will be of the form "x:y" where x is an integer between 1 and 12, inclusive, and y is an integer between 00 and 59, inclusive.
  • There are no leading zeros on the hours portion of the time.
  • There is exactly one leading zero if the minutes is between 0 and 9, otherwise no leading zeros (for example, 12:00, 12:01, 12:09, etc).
Examples
0)
"12:00"
Returns: "12:00"
1)
"10:45"
Returns: "1:15"
2)
"3:07"
Returns: "8:53"
3)
"2:00"
Returns: "10:00"
4)
"11:59"
Returns: "12:01"

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

Coding Area

Language: C++17 · define a public class Mirror with a public method string mirror(string time) · 32 test cases · 2 s / 256 MB per case

Submitting as anonymous