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 (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.

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[];
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 ;
}

最新文章

  1. mysql default unix_timestamp(now())
  2. hdu4135 容斥定理
  3. PoEdu - C++阶段班【Po学校】- Lesson03-4_构造函数&amp;赋值函数&amp;拷贝构造函数&amp;学习方式 - 第6天
  4. filter的详细配置
  5. javascript平时小例子③(setInterval使用1)
  6. ASP.NET 中通过Form身份验证 来模拟Windows 域服务身份验证的方法
  7. ubuntu下修改mysql默认字符编码出现的Job failed to start解决办法
  8. RHEL7.2下netcat工具安装教程
  9. 【转】iOS代码规范
  10. WINDOWS 下搭建 OC 集成开发环境
  11. codeforces gym 100187M Heaviside Function
  12. ansible变量
  13. 高级UIKit-03(NSFileManager、NSFileHandle)
  14. vuejs 父组件向子组件传递($broadcast()的用法)
  15. LINUX RHEL6.5字符界面安装图形化桌面
  16. JVM基础篇(一)
  17. Oracle技术面试问题
  18. 【opencv实践】边缘检测
  19. TTL集成门电路
  20. js内存空间的那点事

热门文章

  1. softmax-Fork
  2. Eqaulize Prices
  3. bootstrap的字体设置
  4. C++四种初始化方式
  5. 如何将mongo查询结果导出到文件中
  6. truffle编译合约常见问题及其在私链上的部署与交互
  7. Bash Game hdu 1846
  8. Python turtle库详解
  9. ALSA driver基本概念
  10. C#中发ref和out