欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2182A.New Year String
New Year String
We will call a string consisting of characters 0, 2, 5, and/or 6 a New Year string if at least one of the two conditions is met:
- it contains the string
2026as a continuous substring; - it does not contain the string
2025as a continuous substring.
For example, the strings 20252026, 21026, 20262026, 000 are New Year strings. The strings 2025, 20256, 20252025, 000202500020226 are not New Year strings.
You are given a string . You can perform the following operation any number of times (possibly zero):
- choose a character in the string and replace it with
0,2,5, or6(you can choose any one of these four characters).
Calculate the minimum number of operations needed to make the string a New Year string.
Input
The first line contains one integer () — the number of test cases.
Each test case consists of two lines:
- the first line contains one integer () — the number of characters in ;
- the second line contains — a sequence of characters
0,2,5, and/or6.
Output
For each test case, output one integer — the minimum number of operations needed to make the string a New Year string.
Note
In the second example from the statement, you can replace the -nd character of the string with 2. Then the string will become 2225.
In the fifth example from the statement, you can replace the -th character with 6. Then the string will become 20262025.
In the sixth example from the statement, you can replace the -th character with 6. Then the string will become 202520266.
Samples
7
4
0000
4
2025
4
2026
8
20252026
8
20252025
9
202520256
9
202520265
0
1
0
0
1
1
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |