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

    贪心 这个贪心不太懂啊 dfs返回子树需要的最小值,然后按需要减消耗排序,然后贪心选取即可. #include<bits/stdc++.h> using namespace std; ty ...

  2. Spring Boot 特性 —— SpringApplication

    转自:https://blog.csdn.net/cqdz_dj/article/details/52910317

  3. PCB MongoDb安装与Windows服务安装

    工程MI流程指示做成Web网页形式,采用MVC框架制作,数据传输用Web API方式, 最终此网页会挂到公司各系统中访问,为了提高访问并发量,并将工程数据统一结构化管理, 采用No SQL Mongo ...

  4. 使用 Polyfill 而不再是 bable 来实践js新特性

    现状 我们想要用ES6 语法来写 JavaScript.然而由于我们需要兼容老版本的浏览器,那些浏览器不支持 ES6,我们需要解决这个问题. 有一个标准的做法是:写 ES6 代码 → 将所有代码编译成 ...

  5. Moon Http Server,强大如斯的全脚本web服务器

    Moon Http Server(MHS) 是一个使用Pascal脚本的高性能Web服务器. 昨天晚上是第一次接触.花了30分钟入门,非常强大.是Delphi 者开发Web的福音. 引用一下作者的介绍 ...

  6. HDU3533 Escape

    题目: The students of the HEU are maneuvering for their military training. The red army and the blue a ...

  7. 消除svn选定(checkout)桌面上文件显示一大堆问号。

    图片: 解决方法一: 桌面右键选择TortoiseSVN——>点击Settings,如下图,选中Icon Overlays(图标覆盖),去勾选Fixed drives(本地磁盘),点击确定,按F ...

  8. pinpoint 磁盘不足的坑

    观察 pinpoint hbase 数据存储目录default中各个表的大小 TraceV2 15G ApplicationTraceIndex 15G major_compact的操作目的 合并文件 ...

  9. 【Android】实例 忐忑的精灵

    在Android Studio中创建项目,名称为“Animation And Multimedia”,然后在该项目中创建一个Module,名称为“Frame-By-Frame Animation”.在 ...

  10. 01--Java IO基础

    一.java.io包概览 Java IO包主要可以分为如下4类: 基于字节操作的I/O接口:InputStream和OutputStream. 基于字符操作的I/O接口:Writer和Reader 基 ...