#P16291. [蓝桥杯 2026 省 Java A 组] 连续打卡
[蓝桥杯 2026 省 Java A 组] 连续打卡
Problem Description
Xiaoming is a self-disciplined programmer. He uses a learning check-in app every day to record his study progress. The app records the date of each check-in. Now Xiaoming wants to find his longest streak of consecutive check-in days.
A consecutive check-in means that there is a check-in record on every day within a continuous range of days. For example, if Xiaoming checked in on 2026-01-01, 2026-01-02, and 2026-01-03, then this is a streak of consecutive days.
Given Xiaoming's check-in records (a number of dates), compute the maximum number of consecutive check-in days.
Note: If none of the check-in dates are adjacent, then the longest consecutive check-in days is . That is, a single day is also considered a streak of day.
Note: The check-in records may contain duplicates (multiple check-ins on the same day). Multiple check-ins on the same day count as one day only.
Input Format
The first line contains an integer , representing the number of check-in records.
The next lines each contain a date in the format YYYY-MM-DD (year-month-day).
Output Format
Output one integer, representing the maximum number of consecutive check-in days.
7
2026-01-01
2026-01-02
2026-01-03
2026-01-05
2026-01-06
2026-01-10
2026-01-02
3
5
2025-12-30
2025-12-31
2026-01-01
2026-01-02
2026-01-03
5
Hint
Sample Explanation 1
After removing duplicates, Xiaoming's check-in dates are: 2026-01-01, 2026-01-02, 2026-01-03, 2026-01-05, 2026-01-06, 2026-01-10.
Among them:
- 2026-01-01 to 2026-01-03 are consecutive days.
- 2026-01-05 to 2026-01-06 are consecutive days.
- 2026-01-10 is a single streak of day.
Therefore, the longest consecutive check-in days is .
Sample Explanation 2
These days are consecutive dates across two years, from December 30, 2025 to January 3, 2026, for a total of consecutive check-in days.
Constraints and Evaluation Rules
For all testdata:
- .
- Date range: 2000-01-01 to 2099-12-31.
- All dates are guaranteed to be valid (including leap years).
- Dates may be given in any order and may contain duplicates.
| Testdata Percentage | Data Size |
|---|---|
| 30% | |
| 60% | |
| 100% |
Translated by ChatGPT 5