CodeForces C. Detective Task(思路超简单)

Polycarp bought a new expensive painting and decided to show it to his nn friends. He hung it in his room. nn 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 nn-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 tt (1≤t≤1041≤t≤104) — 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 ss (length does not exceed 2⋅1052⋅105) — a description of the friends' answers, where sisi indicates the answer of the ii-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 2⋅1052⋅105.

Output

Output one positive (strictly more zero) number – the number of people who could steal the picture based on the data shown.

Example

input

Copy

8
0
1
1110000
?????
1?1??0?0
0?0???
??11
??0??

output

Copy

1
1
2
5
4
1
1
3

Note

In the first case, the answer is 11 since we had exactly 11 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.

思路:首先我们要清楚一点!也是最重要的一点!那就是input里不会先出现了0再出现1;这个的证明很简单,我们举个例子要是是01的画,我们假设第一个人是小偷,可是第二个肯定就是好人,这显然矛盾,假设第二个人也是小偷也是如此,那么我们就可以发现,在最后一个1到第一个0之间的人都有可能是小偷!那么就很简单了!

#include <bits/stdc++.h>
using namespace std;
const int N =2e5+10;
#define endl '\n'
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int m;cin>>m;
    while(m--){
        string s;
        cin>>s;
        int cnt=0;
        for(int i=0;i<s.size();i++){//从前往后读到第一个0;
            if(s[i]=='0'){//读到之后就找前面的1;
                for(int j=i;j>=0;j--){
                    cnt++;
                    if(s[j]=='1')break;//找到了就break;
                }
                break;//找不到也要break;因为之前的人可能都是坏人
            }
        }
        if(cnt)cout<<cnt<<endl;//要是找到了一个0那么肯定cnt不是0个
        else{//因为可能有没有0的情况!那我们就从最后从前找第一个1就好了
            for(int i=s.size()-1;i>=0;i--){
                cnt++;
                if(s[i]=='1')break;
            }
            cout<<cnt<<endl;
        }
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值