Digory Kirke and Polly Plummer are two kids living next door to each other. The attics of the two houses are connected to each other through a passage. Digory's Uncle Andrew has been secretly doing strange things in the attic of his house, and he always ensures that the room is locked. Being curious, Digory suspects that there is another route into the attic through Polly's house, and being curious as kids always are, they wish to find out what it is that Uncle Andrew is secretly up to.
So they start from Polly's house, and walk along the passageway to Digory's. Unfortunately, along the way, they suddenly find that some of the floorboards are missing, and that taking a step forward would have them plummet to their deaths below.
Dejected, but determined, they return to Polly's house, and decide to practice long-jumping in the yard before they re-attempt the crossing of the passage. It takes them exactly one day to master long-jumping a certain length. Also, once they have mastered jumping a particular length L, they are able to jump any amount less than equal to L as well.
The next day they return to their mission, but somehow find that there is another place further up the passage, that requires them to jump even more than they had practiced for. So they go back and repeat the process.
Note the following:
Find how many days it will take them to cross the passageway. In the input, the passageway is described as a string P of '#'s and '.'s. A '#' represents a floorboard, while a '.' represents the absence of a floorboard. The string, when read from left to right, describes the passage from Polly's house to Digory's, and not vice-versa.
The first line consists of a single integer T, the number of testcases.
Each of the next T lines consist of the string P for that case.
For each case, output the number of days it takes them to cross the passage.
Input: 4 #### ##.#..# ##..#.# ##.#....# Output: 0 2 1 2
#pragma once
#include <stdio.h>
class AtticCrossing
{
const static int MAX_BU = 5120;
const static int FLASH_P = MAX_BU - 12;
int st, len, oSt;
char inBuffer[MAX_BU];
char outBuffer[MAX_BU];
char getFromBuf()
{
if (st >= len)
{
len = fread(inBuffer, 1, MAX_BU, stdin);
st = 0;
}
return inBuffer[st++];
}
void intToBuf(int n, char sep)
{
if (oSt >= FLASH_P)
{
fwrite(outBuffer, 1, oSt, stdout);
oSt = 0;
}
if (0 == n)
{
outBuffer[oSt++] = '0';
outBuffer[oSt++] = sep;
return;
}
int i = oSt;
while (n)
{
outBuffer[oSt++] = n % 10 + '0';
n /= 10;
}
int j = oSt-1;
while (i < j)
{
char t = outBuffer[i];
outBuffer[i] = outBuffer[j];
outBuffer[j] = t;
i++, j--;
}
outBuffer[oSt++] = sep;
}
void FlashLeft()
{
if (oSt) fwrite(outBuffer, 1, oSt, stdout);
}
public:
AtticCrossing() : st(0), len(0), oSt(0)
{
int T = 0, curJump = 0, curGap = 0, days = 0;
scanf("%d", &T);
getchar();
char c;
while (T--)
{
curJump = 0, curGap = 0, days = 0;
while (c = getFromBuf())
{
if ('.' == c) curGap++;
else if (curGap)
{
if (curJump < curGap) days++, curJump = curGap;
curGap = 0;
}
if ('\n' == c || !len) break;
}
intToBuf(days, '\n');
}
FlashLeft();
}
};
int atticCrossing()
{
AtticCrossing();
return 0;
}