Grid and phrase

3.7

43 votes
Arrays, Brute-force search, Data Structures, Easy, Multi-dimensional
Problem

You are given an n*m grid which contains lower case English letters. How many times does the phrase "saba" appear horizontally, vertically, and diagonally in the grid?

Input format

  • First line: Two integer n and m, where n denotes (1 <= n,m <= 100) the number of rows and m denotes the number of columns in the grid
  • Next n lines: Each line must contain a string of length m which contains lower-case English letters only

Output format

Print the number of times the word “saba” appears in the grid.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The phrase "saba" must look one of thease shapes :

s      
  a    
    b  
      a

 

s a b a
       
       
       

 

s      
a      
b      
a      

 

      a
    b  
  a    
s      

 

Editor Image

?