The Little Elephant from the Zoo of Lviv currently is on the military mission. There are N enemy buildings placed in a row and numbered from left to right strating from 0. Each building i (except the first
and the last) has exactly two adjacent buildings with indices i-1 and i+1. The first and the last buildings have just a single adjacent building.

Some of the buildings contain bombs. When bomb explodes in some building it destroys it and all adjacent to it buildings.

You are given the string S of length N, where Si is 1 if the i-th building contains bomb, 0 otherwise. Find for the Little Elephant the number of
buildings that will not be destroyed after all bombs explode. Please note that all bombs explode simultaneously.

Input

The first line contains single integer T - the number of test cases. T test cases follow. The first line of each test case contains the single integer N - the number of buildings. The next line contains the
string S of lengthN consisted only of digits 0 and 1.

Output

In T lines print T inetgers - the answers for the corresponding test cases.

Constraints

1 <= T <= 100

1 <= N <= 1000

Example

Input:
3
3
010
5
10001
7
0000000 Output:
0
1
7

字符串的操作问题。

推断方法非常多种。注意头尾的特殊情况就能够了。

#pragma once
#include <stdio.h>
#include <vector>
#include <iostream>
using namespace std; class LittleElephantandBombs
{
public:
LittleElephantandBombs()
{
int T = 0, N = 0;
scanf("%d", &T);
char s[1001];
while (T--)
{
scanf("%d", &N);
scanf("%s", &s);
char *p = &s[0];
int c = 0;
while (*p)
{
if (*p == '1' && *(p+1) == '0') p += 2;
else if (*p == '0' && *(p+1) != '1') c++, p++;
else p++;
}
printf("%d\n", c);
}
}
}; int littleElephantandBombs()
{
LittleElephantandBombs();
return 0;
}

codechef Little Elephant and Bombs题解的更多相关文章

  1. codechef Little Elephant and Permutations题解

    The Little Elephant likes permutations. This time he has a permutation A[1], A[2], ..., A[N] of numb ...

  2. CodeChef November Challenge 2013 部分题解

    http://www.codechef.com/NOV13 还在比...我先放一部分题解吧... Uncle Johny 排序一遍 struct node{ int val; int pos; }a[ ...

  3. CodeChef Little Elephant and Movies [DP 排列]

    https://www.codechef.com/FEB14/problems/LEMOVIE 题意: 对于一个序列,定义其“激动值”为序列中严格大于前面所有数的元素的个数.给定n个数p1;,p2.. ...

  4. CodeChef Little Elephant and Mouses [DP]

    https://www.codechef.com/problems/LEMOUSE 题意: 有一个n *m的网格.有一头大象,初始时在(1,1),要移动到(n,m),每次只能向右或者向下走.有些格子中 ...

  5. codechef February Challenge 2018 简要题解

    比赛链接:https://www.codechef.com/FEB18,题面和提交记录是公开的,这里就不再贴了 Chef And His Characters 模拟题 Chef And The Pat ...

  6. codechef Row and Column Operations 题解

    版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...

  7. codechef January Lunchtime 2017简要题解

    题目地址https://www.codechef.com/LTIME44 Nothing in Common 签到题,随便写个求暴力交集就行了 Sealing up 完全背包算出得到长度≥x的最小花费 ...

  8. codechef January Challenge 2017 简要题解

    https://www.codechef.com/JAN17 Cats and Dogs 签到题 #include<cstdio> int min(int a,int b){return ...

  9. codechef Sums in a Triangle题解

    Let's consider a triangle of numbers in which a number appears in the first line, two numbers appear ...

随机推荐

  1. 第1课 Git、谁与争锋

    1-1  安装和使用Git http://git-scm.com/downloads Git的指令模式,才能够清楚地了解Git的工作细节.最后还会介绍Git Server的架设和管理,让读者能够熟练使 ...

  2. 关于MFC控件删除出现“具有该ID的控件已存在”这样的情况的解决方案,详细,网上都没有这么详细的,我是“深受其害”,所以想将详细的方法分享出去。

    网上关于MFC控件删除出现“具有该ID的控件已存在”这样的情况,在网上找了很多关于这方面的东西,但是都不是很全,也不容易弄明白.现在问我直接通过一个项目和图片的形式和大家一块分享一个这个解决方法(如有 ...

  3. Windows:Word,PPT,EXCEL com+组件配置

    本文所涉及到配置前提: 服务器必须安装Office套件(Word,PPT,Excel) 第一部分 Word Com+组件权限配置 1.cmd模式输入dcomcnfg 2.找到Microsoft Wor ...

  4. BZOJ 4563 错排+高精度

    思路: 把障碍移到对角线 就发现 这是个错位排列问题 用错排公式即可解 s[i]=(s[i-1]+s[i-2])*i //By SiriusRen #include <cstdio> #i ...

  5. ruby --Paperclip::NotIdentifiedByImageMagickError

    首先,如果遇到这个问题,Paperclip::NotIdentifiedByImageMagickError,先检查下环境变量是否配置了ImagicMagick的路径. cmd下path 查看,首先加 ...

  6. node js koa js严格模式

      当前为配置 非原创 引用于“得金” ### nodejs项目配置终端命令 1. 检查本地 nodejs 版本`$node -v` 如果版本低就升级 2. 安装 n 升级命令 `$npm insta ...

  7. Asp.net MVC Checkbox控件 和 Nullable<bool>, 或bool?类型

    @Html.CheckBoxFor() 这个方法生成两个Input HTML标签,不明白为什么这样,如果数据库是Nullable<bool>类型,就会报错. 网上的解决方法是这样: 方法一 ...

  8. javascript执行环境及作用域

    执行环境(execution context,为简单起见,有时也成为“环境”)是javascript中最为重要的一个概念.执行环境定义了变量或函数有权访问的其他数据,决定了它们各自的行为.每个执行环境 ...

  9. Oracle SQL 性能优化技巧

    Select语句完整的执行顺序: SQL Select语句完整的执行顺序: 1. from子句组装来自不同数据源的数据: 2.where子句基于指定的条件对记录行进行筛选: 3.group by子句将 ...

  10. Linux rsync配置用于服务器之间传输大量的数据

    Linux的rsync 配置,用于服务器之间远程传大量的数据   [教程主题]:rsync [课程录制]: 创E [主要内容] [1] rsync介绍 Rsync(Remote Synchronize ...