Problem statement: https://www.hackerrank.com/contests/ncr-codesprint/challenges/spiral-message
You've intercepted an encoded spy message! The message originated as a single line of one or more space-separated words, but it was encoded into an matrix as a clockwise spiral starting in the lower left-hand corner. For example, the diagram below shows the decoding process for an encoded message:
The message is decoded spirally starting from the lower left-hand corner of the matrix and moving in the clockwise direction (i.e., up, right, down, left, up, right, etc.). From the starting position, you must clockwise-traverse the matrix, scanning characters and switching to the next clockwise direction each time you reach a boundary (i.e., an already-scanned character or the end of the matrix). Continue scanning characters in this manner until you've scanned all the matrix's characters into a single decoded string. The word separator for the decoded string is the hash mark (#).
Given , , and an encoded message, decode the message and print the number of words in the decoded message.
Input Format
The first line contains two space-separated positive integers describing the respective values of and . Each line of the subsequent lines contains a string of characters describing row of the encoded message.
Constraints
Each word consists of lowercase English alphabetic characters (a to z). The encoded message consists of words and hash marks (#). Each hash mark denotes a single space. Output Format
Print an integer denoting the number of decoded words.
Sample Input
3 5 a##ar a#aa# xxwsr Sample Output
4 Explanation
The diagram at the top of the challenge demonstrates the decoding process for the given Sample Input. The decoded message is xaa##ar#rswx#aa. Because hash marks denote spaces, we can break the message into four words: xaa, ar, rswx, and aa. Thus, we print as our answer.
Problem statement: https://www.hackerrank.com/contests/ncr-codesprint/challenges/spiral-message
You've intercepted an encoded spy message! The message originated as a single line of one or more space-separated words, but it was encoded into an matrix as a clockwise spiral starting in the lower left-hand corner. For example, the diagram below shows the decoding process for an encoded message:
The message is decoded spirally starting from the lower left-hand corner of the matrix and moving in the clockwise direction (i.e., up, right, down, left, up, right, etc.). From the starting position, you must clockwise-traverse the matrix, scanning characters and switching to the next clockwise direction each time you reach a boundary (i.e., an already-scanned character or the end of the matrix). Continue scanning characters in this manner until you've scanned all the matrix's characters into a single decoded string. The word separator for the decoded string is the hash mark (#).
Given n, m, and an encoded message, decode the message and print the number of words in the decoded message.
Input Format
The first line contains two space-separated positive integers describing the respective values of n and m. Each line i of the n subsequent lines contains a string of m characters describing row i of the encoded message.
Constraints
Each word consists of lowercase English alphabetic characters (a to z). The encoded message consists of words and hash marks (#). Each hash mark denotes a single space. 0<n,m<=20 Output Format
Print an integer denoting the number of decoded words.
Sample Input
3 5
a##ar
a#aa#
xxwsr
Sample Output
4
Explanation
The diagram at the top of the challenge demonstrates the decoding process for the given Sample Input. The decoded message is xaa##ar#rswx#aa. Because hash marks denote spaces, we can break the message into four words: xaa, ar, rswx, and aa. Thus, we print 4 as our answer.
