Roman loved diamonds. Monica decided to give him a beautiful gift on Valentine's Day.…
- User
Roman loved diamonds. Monica decided to give him a beautiful gift on Valentine's Day. Her idea of diamonds was different though. She lit up all the windows of her rectangular building with N floors and M windows on each floor, with 2 shapes - / or \ . According to her, a diamond was made when such a shape was created:
/
/Given the shape of lights in all the windows, help Roman count the number of diamonds formed. Note: The components of the diamond should be adjacent to each other. Input: First line contains T - the number of testcases. For each testcase, First line contains 2 space-separated positive integers - N and M - the no. of floors in the building and the no. of windows on each floor respectively. N lines follow - each line contains M space-separated characters. Every character is either or / .
Output: Print a single integer - the total no. of diamonds formed.
Constraints: 1 ≤ T ≤ 5 2 ≤ N, M ≤ 1000
SAMPLE INPUT 1 2 4 / \ /
\ / \ /SAMPLE OUTPUT 2
Assistant
pythonimport sys def count_diamonds(): t = int(sys.stdin.readline()) for _ in range(t): n, m = map(int, sys.stdin.readline().split()) grid = [sys.stdin.readline().split() for _ in range(n)] count = 0 for i in range(n - 1): for j in range(m - 1): if (grid[i][j] == '/' and grid[i][j+1] == '\\' and grid[i+1][j] == '\\' and grid[i+1][j+1] == '/'): count += 1 print(count) if __name__ == "__main__": count_diamonds()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.