Detective Task - CodeForces 1675C - Virtual Judge (csgrandeur.cn)
题意:有一副画被一个小偷偷了,小偷在n个人当中,每个人都会说一句话:
- 否(0)表示在他进入房间内没有看到画;
- 是(1)看到;
- 不记得(?)不知道;
找出可疑人数
思路:找到字符串中出现1的位置,且在第一次出现0的位置的前面,小偷肯定在这个区间内
需要特判一开始说1和最后说0,和只有一个人的情况,因为这些情况小偷一定是这个人
code
#include<bits/stdc++.h>
#define x first
#define y second
#define mak make_pair
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(a) cout<<a<<'\n'
#define endl '\n'
#define umap unordered_map
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N=1e5+10,M=1,inf=0x3f3f3f3f,mod=1e9+7;
int t;
void solve()
{
string a;cin>>a;
int len=a.size();
if(a[0]=='0'||a[len-1]=='1'||len==1)
{
cout<<1<<endl;
return;
}
int pos1=0,pos0=len-1;
for(int i=0;i<len;i++)
{
if(a[i]=='1')
{
pos1=i;
}
else if(a[i]=='0')
{
pos0=i;
break;
}
}
cout<<pos0-pos1+1<<endl;
}
int main()
{
IOS;
cin>>t;
while(t--)
{
solve();
}
return 0;
}