Placement of lights

Title Description

Q is a small length of road design to the resettlement program n the street.

To make things simple, small road viewed as the Q n squares, where required to illuminate with '.' Means no need to illuminate the obstacle lattice is represented by 'X'.

Q small now set up some lights on the road, placed in pos for position lights, street lamps which can illuminate pos - 1, pos, pos + 1 three positions.

Q little hope to minimize the placement of lights illuminate all. '' Area, I hope you can help him calculate how many streetlights requires a minimum.
Enter a description:

The first line of input contains a positive integer t (1 <= t <= 1000), represents the number of test cases
next test data every two lines, a line of a first positive integer n (1 <= n <= 1000), It represents the length of the road.
The second row shows the structure of a string s roads, comprising only '' and 'X-'.

Output Description:

For each test case, output a positive integer requires a minimum number of streetlights.

#include <iostream>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        char a[1003];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
           // cout<<a[i];
        }
        int num=0;
      for(int i=0;i<n;i++)
      {
          int cnt=0;
          if(a[i]=='.')
         {
              num++;
              i=i+2;
         }
      }
      cout<<num<<endl;

    }
    return 0;
}

Published 39 original articles · won praise 7 · views 3052

Guess you like

Origin blog.csdn.net/zzyzzylalala/article/details/104104602