cswork / OA打开练习工作台

StripeOA #18

Generate Available Time Slots

估计中等可在线判题

考点(AI 标注)模拟/实现字符串

Given a closed date-time range and working periods that repeat weekly, output all complete 30-minute time slots within the range. A slot must lie entirely within the range and within the corresponding working period. Each working period's slot grid starts at the period's start and produces a candidate slot every 30 minutes; identical slots produced by repeated periods are output only once.

输入格式

The first two lines are the start and end times, in the format YYYY-MM-DD HH:MM; the third line contains the number of working periods w, followed by w lines of weekday start end. weekday ranges from 0 (Monday) to 6 (Sunday); times are HH:MM, and the end may be written as 24:00. Each period is a same-day half-open interval [start,end) with start < end. The range spans at most 366 days, and 0≤w≤1000.

输出格式

First output the number of time slots; then output one <start time>,<end time> per line in ascending time order. If there are no available slots, output only 0.

样例 1

输入:

2026-01-05 09:10
2026-01-05 10:40
1
0 09:00 12:00

输出:

2
2026-01-05 09:30,2026-01-05 10:00
2026-01-05 10:00,2026-01-05 10:30

样例 2

输入:

2026-01-05 08:00
2026-01-12 10:00
1
0 09:00 10:30

输出:

5
2026-01-05 09:00,2026-01-05 09:30
2026-01-05 09:30,2026-01-05 10:00
2026-01-05 10:00,2026-01-05 10:30
2026-01-12 09:00,2026-01-12 09:30
2026-01-12 09:30,2026-01-12 10:00

样例 3

输入:

2026-01-05 10:00
2026-01-05 10:30
1
0 10:00 10:30

输出:

1
2026-01-05 10:00,2026-01-05 10:30