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?
The first line contains one integer tt (1≤t≤1001≤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.
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).
3
010011
0
1111000
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[];
scanf("%s",s);
int i;
vector<int>v;
int ans=;
for(i=;i<strlen(s);i++)
{
if(s[i]=='')v.push_back(i);
}
if(v.size()==||v.size()==||strlen(s)==)
{
cout<<<<endl;
continue;
}
for(i=;i<v.size()-;i++)
{
if(v[i+]-v[i]!=)ans+=(v[i+]-v[i]-);
}
cout<<ans<<endl;
}
return ;
}
Educational Codeforces Round 82 A. Erasing Zeroes的更多相关文章
- Educational Codeforces Round 82 (Rated for Div. 2) A-E代码(暂无记录题解)
A. Erasing Zeroes (模拟) #include<bits/stdc++.h> using namespace std; typedef long long ll; ; in ...
- [CF百场计划]#3 Educational Codeforces Round 82 (Rated for Div. 2)
A. Erasing Zeroes Description You are given a string \(s\). Each character is either 0 or 1. You wan ...
- 【题解】Educational Codeforces Round 82
比较菜只有 A ~ E A.Erasing Zeroes 题目描述: 原题面 题目分析: 使得所有的 \(1\) 连续也就是所有的 \(1\) 中间的 \(0\) 全部去掉,也就是可以理解为第一个 \ ...
- Educational Codeforces Round 82 (Rated for Div. 2)
题外话 开始没看懂D题意跳了,发现F题难写又跳回来了.. 语文好差,码力好差 A 判第一个\(1\)跟最后一个\(1\)中\(0\)的个数即可 B 乘乘除除就完事了 C 用并查集判一下联通,每个联通块 ...
- Educational Codeforces Round 82 (Rated for Div. 2)E(DP,序列自动机)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],t[]; int n,m; ][]; ...
- Educational Codeforces Round 82 (Rated for Div. 2)D(模拟)
从低位到高位枚举,当前位没有就去高位找到有的将其一步步拆分,当前位多余的合并到更高一位 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h&g ...
- Educational Codeforces Round 82 C. Perfect Keyboard
Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him ...
- Educational Codeforces Round 82 B. National Project
Your company was appointed to lay new asphalt on the highway of length nn. You know that every day y ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
随机推荐
- Attribute "resultType" must be declared for element type "update" or "insert"
仔细查看错误如图所示: 解决错误就是把resultType去掉,因为在insert和update语句中是没有返回值的.小坑小坑 转自:https://blog.csdn.net/u013144287/ ...
- Oracle空表的分配segment
1.查询相关参数deferred_segment_creation select * from v$parameter where name='deferred_segment_creation' ...
- Word2010如何从指定页设置页码
光标定位:将光标定位于需要开始编页码的页首位置. 插入分隔符的”下一页”:选择“页面布局—>分隔符—> 下一页”插入. 插入页码:选择“插入—>页码—> 页面底端”,选 ...
- 自定义php-mysqli工具增强类,支持链式调用
<?php /*数据库访问类,支持链式访问 *function table($table):表名 *function where($where):条件 *function field(...$f ...
- Flask 教程 第十七章:Linux上的部署
本文翻译自The Flask Mega-Tutorial Part XVII: Deployment on Linux 这是Flask Mega-Tutorial系列的第十七部分,我将把Microbl ...
- Java - 集合 - List
1.List实现类:ArrayList.LinkedList.Vector ArrayList使用: void test() { //声明 List<String> testlist = ...
- 吴裕雄 python 机器学习——支持向量机线性分类LinearSVC模型
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets, linear_model,svm fr ...
- class实现React继承以及constructor的super的问题
看这篇文章之前 建议先看看阮一峰 的Class继承 便于更好的理解 首先要知道一个问题 React的父子组件和组件类的继承有什么关系?答案是:没有关系 父子组件:指的得是组件标签包含关系 父子组件通过 ...
- MySQL 学习(三)事务学习
事务隔离级别 SQL标准的事务隔离级别包括:读未提交(read uncommitted).读提交(read committed).可重复读(repeatable read)和串行化(seria ...
- go基础_函数
函数的基本写法 func add(a int, b int) int { return a + b } 如果2个参数的类型一样,可以简写为 func add(a, b int) int { retur ...