Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 200 点
問題文
高橋君は置き時計を買いました。
この時計は、現在の時刻が 24 時制で \mathrm{AB} 時 \mathrm{CD} 分であるときに図 1 のように時刻を表します。
例えば図 2 では、時計は 7 時 58 分を示しています。
時刻の表示方法をより形式的に説明すると次のようになります。
現在の時刻が 24 時制で h 時 m 分であるとします。ここで 24 時制とは、時間を 0 以上 23 以下の整数で、分を 0 以上 59 以下の整数で表す時刻の表現方法を言います。
h の 10 の位を A, 1 の位を B, m の 10 の位を C, 1 の位を D とします。(ただし h, m が 1 桁である場合は先行ゼロを追加して考えます。)
このとき時計は左上に A を、左下に B を、右上に C を、右下に D を表示します。
高橋君は、次の条件を満たす時刻を 見間違えやすい時刻 と呼ぶことにしました。
- 時計の表示の右上と左下を入れ替えても、それに対応する 24 時制の時刻が存在する。
例えば 図 3 は 20 時 13 分を示していますが、時計の表示の右上と左下を入れ替えると 21 時 3 分を意味する表示になります。よって 20 時 13 分は見間違えやすい時刻です。
今、時計は H 時 M 分を示しています。
(現時点も含めて)以降はじめて訪れる見間違えやすい時刻を 24 時制で答えてください。
制約
- 0 \leq H \leq 23
- 0 \leq M \leq 59
- H, M は整数
入力
入力は以下の形式で標準入力から与えられる。
H M
出力
答えを h 時 m 分とする。ここで h, m は 0 \leq h \leq 23, 0 \leq m \leq 59 である必要がある。
このとき h, m を以下の形式で出力せよ。
h m
なお、h, m を 2 桁に揃えるために先行ゼロをつけた形式で出力しても正答と見なされる。
入力例 1
1 23
出力例 1
1 23
1 時 23 分は見間違えやすい時刻です。なぜならば、時計の表示の右上と左下を入れ替えると 2 時 13 分を意味する表示になるからです。
よって答えは 1 時 23 分です。
なお、01 23
のように先行ゼロをつけた形式で出力しても正答として扱われます。
入力例 2
19 57
出力例 2
20 0
19 時 57 分以降ではじめて訪れる見間違えやすい時刻は 20 時 0 分です。
入力例 3
20 40
出力例 3
21 0
24 時制では 24 時 0 分という表記は合法でないのに注意してください。
Score : 200 points
Problem Statement
Takahashi bought a table clock.
The clock shows the time as shown in Figure 1 at \mathrm{AB}:\mathrm{CD} in the 24-hour system.
For example, the clock in Figure 2 shows 7:58.
The format of the time is formally described as follows.
Suppose that the current time is m minutes past h in the 24-hour system. Here, the 24-hour system represents the hour by an integer between 0 and 23 (inclusive), and the minute by an integer between 0 and 59 (inclusive).
Let A be the tens digit of h, B be the ones digit of h, C be the tens digit of m, and D be the ones digit of m. (Here, if h has only one digit, we consider that it has a leading zero; the same applies to m.)
Then, the clock shows A in its top-left, B in its bottom-left, C in its top-right, and D in its bottom-right.
Takahashi has decided to call a time a confusing time if it satisfies the following condition:
- after swapping the top-right and bottom-left digits on the clock, it still reads a valid time in the 24-hour system.
For example, the clock in Figure 3 shows 20:13. After swapping its top-right and bottom-left digits, it reads 21:03. Thus, 20:13 is a confusing time.
The clock now shows H:M.
Find the next confusing time (including now) in the 24-hour system.
Constraints
- 0 \leq H \leq 23
- 0 \leq M \leq 59
- H and M are integers.
Input
The input is given from Standard Input in the following format:
H M
Output
Let h:m be the answer, where h and m must satisfy 0 \leq h \leq 23 and 0 \leq m \leq 59.
Print h and m in the following format:
h m
Your answer is considered correct even if h contains a leading zero to represent it as a 2-digit integer; the same applies to m.
Sample Input 1
1 23
Sample Output 1
1 23
1:23 is a confusing time because, after swapping its top-right and bottom-left digits on the clock, it reads 2:13.
Thus, the answer is 1:23.
Your answer is considered correct even if you print 01 23
with a leading zero.
Sample Input 2
19 57
Sample Output 2
20 0
The next confusing time after 19:57 is 20:00.
Sample Input 3
20 40
Sample Output 3
21 0
Note that 24:00 is an invalid notation in the 24-hour system.