Page 4 of 4
Re: 271 - WA
Posted: Wed Jan 08, 2014 3:20 am
by brianfry713
Print a newline char at the end of the last line.
Re: 271 - Simply Syntax
Posted: Fri Feb 12, 2016 12:36 pm
by TryCatchMe
Hello all,
First of all, you can do this problem without recursion. It is solve-able using recursion, but definitely not necessary. A recursive solution may not run in time. I will give you all a hint: use a stack! Also, if you think about the problem you will realize you just need a for loop with no recursive calls.
Secondly, people must understand that you most likely do NOT need to be dynamically allocating memory if using C/C++. Almost every problem statement will tell you the bounds of the problem and if not you can guess-timate it. Dynamically allocating memory is going to slow you down big time. In the hundreds of problems I have solved I have
rarely used dynamic memory allocation (malloc in C, new in C++). Of course the underlying STL data structures may be doing this but I avoid it at all costs.
Third, I have some sample I/O for anyone who is struggling with this problem:
Input
Code: Select all
NNNNNNCst
CNNCstt
CNNNNNNNNCstv
CCNNNNNNNNCstvp
CCNNNNNNNNCstvv
CCNNNCsttt
CCNNNCpqrs
CNst
CCCsttt
s
st
Nst
Csts
CCCstt
NNCssst
sN
st
s
sCst
NNNsCstp
Accepted output:
Code: Select all
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO