Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Statement: Stanley the Slithery Snake loves to eat apples! Given an m x n grid with some apples, he wants to know when he

Problem Statement: Stanley the Slithery Snake loves to eat apples! Given an m x n grid with some apples, he wants to know when he would eat each apple. The m x n grid consists of dots ('.'), which denote empty spaces, and apples ('X'). Stanley slithers in a spiral direction, starting from the top left of the grid moving rightwards, and then spiralling in a clockwise direction once he hits the end of the grid, or hits a place he has travelled before. Given an m x n grid, output all the apples he ate, in order of his moves. Also, you have to specify the coordinates of the ith apple he ate at his ith step, in this format: Apple at (X, Y) eaten at step i Input: Two integers m and n in a single line. 1 <= m, n <= 1000 There will be m lines after, each line containing a string of length n. The string consists of only dots ('.') or apples ('X'). It is guaranteed that the grid consists of at least 1 apple. Output: All the apples that Stanley ate, in order of his moves, in this format: Apple at (X, Y) eaten at step i Each statement should be on a single line. Example: Input: 4 4 .... .X.. .... .... Output: Apple at (1, 1) eaten at step 13

the coding language is java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

. . . Landscape

Answered: 1 week ago