Educational Codeforces Round 82 A. Erasing Zeroes

You are given a string ss. Each character is either 0 or 1.

You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.

You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?

Input

The first line contains one integer tt (1t1001≤t≤100) — the number of test cases.

Then tt lines follow, each representing a test case. Each line contains one string ss (1|s|1001≤|s|≤100); each character of ss is either 0 or 1.

Output

Print tt integers, where the ii-th integer is the answer to the ii-th testcase (the minimum number of 0's that you have to erase from ss).

Example
Input
 
3
010011
0
1111000
Output
 
2
0
0
大意就是问最少删除多少个给定序列里的0能让所有的1都毗连。不妨统计所有1的位置并遍历,发现如果两个1的位置下标的差大于1,则更新答案(不要忘记特判)。
复制代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        char s[105];
        scanf("%s",s);
        int i;
        vector<int>v;
        int ans=0;
        for(i=0;i<strlen(s);i++)
        {
            if(s[i]=='1')v.push_back(i);
        }
        if(v.size()==1||v.size()==0||strlen(s)==1)
        {
            cout<<0<<endl;
            continue;
        }
        for(i=0;i<v.size()-1;i++)
        {
            if(v[i+1]-v[i]!=1)ans+=(v[i+1]-v[i]-1);
        }
        cout<<ans<<endl;
    }
    return 0;
}
复制代码

 



posted @   脂环  阅读(203)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示
主题色彩