A. Erasing Zeroes codeforces1303
A. Erasing Zeroes
You are given a string s. 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 t (1≤t≤100) — the number of test cases.
Then t lines follow, each representing a test case. Each line contains one string s (1≤|s|≤100); each character of s is either 0 or 1.
Output
Print t integers, where the i-th integer is the answer to the i-th testcase (the minimum number of 0’s that you have to erase from s).
Example:
inputCopy
3
010011
0
1111000
outputCopy
2
0
0
Note
In the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
#include<iostream>
#include<string>
using namespace std;
int main()
{int t;//样例个数int c,l,r,i;//c记录0的个数,l为左边第一个不是零的位置,r为右边第一个不是零的位置;cin>>t;string s;while(t--){c=0,l=0,r=0;cin>>s;for(i=0; i<s.size(); i++){if(s[i]=='1'){l=i;break;}}for(i=s.size(); i>=l; i--){if(s[i]=='1'){r=i;break;}}//找到左右两个不为零的端点位置;for(i=l; i<r; i++){if(s[i]=='0')c++;}//找出零的个数## cout<<c<<endl;}
}
A. Erasing Zeroes codeforces1303相关推荐
- Erasing Zeroes CodeForces - 1303A
You are given a string ss. Each character is either 0 or 1. You want all 1's in the string to form a ...
- CodeForces - 1303 A Erasing Zeroes B National Project
A 统计2个1中间0的个数 #include <cstdio> #include <cstring> using namespace std; const int N = 10 ...
- codeforces 1303A Erasing Zeroes 水
https://vjudge.net/problem/CodeForces-1303A 题目大意:给一个 01 01 01串,最最少删去多少个 0 0 0可以使所有的 1 1 1连在一起. #incl ...
- 洛谷CF1303A Erasing Zeroes 题解
description: 给定一个由 0 1 0\ 1 0 1 组成的字符串 s s s. 你需要去掉一些 0 0 0,使得串内所有的 1 1 1 都连续. 问最小去掉的 0 0 0 的个数. 每个输 ...
- 如何做好项目管理工作?
很多项目进度很难把控,经常延期,怎么办?如何跟进整个项目的开发进度.项目测试及项目完成发布? 项目管理三要素:质量.成本和时间 开门见山,项目管理的三要素,是质量.成本和时间. 三要素的意义在于,他们 ...
- 172. Factorial Trailing Zeroes
/**172. Factorial Trailing Zeroes *2016-6-4 by Mingyang* 首先别忘了什么是factorial,就是阶乘.那么很容易想到需要统计* (2,5)对的 ...
- pandas将列表list插入到dataframe的单元格中、pandas使用read_csv函数读取文件并设置保留数值的前置0( leading zeroes)
pandas将列表list插入到dataframe的单元格中.pandas使用read_csv函数读取文件并设置保留数值的前置0( leading zeroes) 目录
- 弱监督语义分割--Object Region Mining with Adversarial Erasing
Object Region Mining with Adversarial Erasing: A Simple Classification to Semantic Segmentation Appr ...
- [LeetCode] Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
最新文章
- ERROR: ld.so: object 'libgtk3-nocsd.so.0' from LD_PRELOAD cannot be preloaded
- Linux串口编程_termios
- 【tomcat】servlet原理及其生命周期
- cdi 2.7.5_看一下CDI 2.0 EDR1
- Order By 排序条件中带参数的写法(Oracle数据库、MyBatis)
- linux 删除含有关键词的文件_linux下查找包含关键字的文件
- 大开眼界百度云盘2018_文化差异的大开眼界
- android 弹出键盘引起的问题
- 『007』MySQL
- 游戏开发之C++内联函数--不受程序员控制的一个函数(C++基础)
- LeetCode题解——Reverse Integer
- 员工离职时,主管应该问相关竞业的两个问题
- Webrtc 屏幕共享
- 元的符号在计算机怎么打出来,告诉你电脑上特殊符号怎么打出来?
- 2021年3月31最新论文(计算机视觉,图像分割,图像识别,图像分类)
- 图像处理学习路线总结 python
- 什么是 AngularJS?
- 2023年全国最新二级建造师精选真题及答案26
- HTML写一个登录框样式
- 复杂网络中重要节点挖掘方法综述