Candy Doctor Changyoung
InterviewTime limit1sMemory limit128 MB
Scan a character grid to count fixed 3-cell horizontal ('>o<') or vertical ('v/o/^') candy patterns.
- Level
Easy3 of 10
- Topics
- Matrix, Implementation, Simulation
- Solved
- No attempts yet
Problem
Changyoung finally got a job. He had not found a workplace he liked until now, but this time he joined a candy factory. He expected working at a candy factory to be sweet, but inspecting candy quality for eight hours turned out to be extremely boring.
Candy quality is inspected as follows. First, open a box full of candies. Then count the number of candies and the number of empty spots.
Unable to endure the boredom, Changyoung decided to write a program for the inspection.
You are given an r by c matrix viewed from above the box. The matrix contains only the following characters.
- "
.": empty spot - "
o": edible part of a candy - "
<>v^": candy wrapper
A candy has only one of the following two shapes.
-
>o< -
v o ^
Only three consecutive characters exactly matching one of these shapes form a candy.
A partial shape, such as >o., may appear, but it is not counted as a candy.
Given the r by c matrix, write a program that prints the number of candies in the box.
Input
The first line contains the number of test cases t. Test cases are separated by a blank line.
For each test case, the first line contains r and c (1 <= r, c <= 400). The next r lines contain the rows of the matrix in order. Each row has exactly c characters and contains only ".o<>v^". Their ASCII values are 46, 111, 60, 62, 118, and 94.
Output
For each test case, print one integer on its own line: the number of candies in the box.
Hint
An input like the following will not be given.
v
>o<
^