欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1675C.Detective Task
Detective Task
Polycarp bought a new expensive painting and decided to show it to his friends. He hung it in his room. of his friends entered and exited there one by one. At one moment there was no more than one person in the room. In other words, the first friend entered and left first, then the second, and so on.
It is known that at the beginning (before visiting friends) a picture hung in the room. At the end (after the -th friend) it turned out that it disappeared. At what exact moment it disappeared — there is no information.
Polycarp asked his friends one by one. He asked each one if there was a picture when he entered the room. Each friend answered one of three:
- no (response encoded with
0); - yes (response encoded as
1); - can't remember (response is encoded with
?).
Everyone except the thief either doesn't remember or told the truth. The thief can say anything (any of the three options).
Polycarp cannot understand who the thief is. He asks you to find out the number of those who can be considered a thief according to the answers.
Input
The first number () — the number of test cases in the test.
The following is a description of test cases.
The first line of each test case contains one string (length does not exceed ) — a description of the friends' answers, where indicates the answer of the -th friend. Each character in the string is either 0 or 1 or ?.
The given regularity is described in the actual situation. In particular, on the basis of answers, at least one friend can be suspected of stealing a painting.
It is guaranteed that the sum of string lengths over the entire input data set does not exceed .
Output
Output one positive (strictly more zero) number – the number of people who could steal the picture based on the data shown.
Note
In the first case, the answer is since we had exactly friend.
The second case is similar to the first.
In the third case, the suspects are the third and fourth friends (we count from one). It can be shown that no one else could be the thief.
In the fourth case, we know absolutely nothing, so we suspect everyone.
Samples
8
0
1
1110000
?????
1?1??0?0
0?0???
??11
??0??
1
1
2
5
4
1
1
3
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |