Canadian Computing Competition: 2005 Stage 1, Junior #5
The term "code monkey" is sometimes used to refer to a programmer who doesn't know much about programming. This is unfair to monkeys, because contrary to popular belief, monkeys are quite smart. They have just been misunderstood. This may be because monkeys do not speak English, but only monkey language. Your job is to help humans and monkeys understand each other by writing a monkey language dictionary. For each word that is typed in, your program must determine whether it is a valid monkey language word.
Unlike in English, spelling in monkey language is very simple. Every word in monkey language satisfies the following rules, and every word satisfying the following rules is a monkey language word.
- A monkey language word is a special type of word called an A-word, which may be optionally followed by the letter
N
and a monkey language word. - An A-word is either only the single letter
A
, or the letterB
followed by a monkey language word followed by the letterS
.
Here are some examples:
- The word
A
is a monkey language word because it is an A-word. - The word
ANA
is a monkey language word because it is the A-wordA
followed by the letterN
and the monkey language wordA
. - The word
ANANA
is a monkey language word because it is the A-wordA
followed by the letterN
and the monkey language wordANA
. - The word
BANANAS
is a monkey language word because it is an A-word, since it is the letterB
followed by the monkey language wordANANA
followed by the letterS
.
Write a program which accepts words, one word on each line, and for each word prints YES
if the word is a monkey language word, and NO
if the word is not a monkey language word. The input word X
indicates the program should terminate, and there is no output for word X
(even though it is not a monkey word).
Sample Input
A
ANA
ANANA
BANANAS
BANANA
X
Sample Output
YES
YES
YES
YES
NO
Comments
This question is insane. 1.B A N B A S S. This one is valid if you parse from outside to inside, but invalid if parse left to right. 2.B A S N B A S. This one is completely opposite. so are they both monkeywords?
Since this question seems to be very confusing, I will try to explain it better.
How to Identify a Monkey Language Word
A
is a monkey language word.N
can separate two monkey language words.N
(likeANA
) are also monkey language words. But if it is not separated by anN
(likeAA
), then it is not a monkey language word.N
to be present in a monkey language word (A
is a monkey langauge word even though there are noN
s).B
andS
can surround a monkey language word.B
must be first andS
must be anywhere after it.B
and anS
to be present in a monkey langauge word (A
is a monkey langauge word even though there are noB
s andS
s).3.Ooo ooo eee eee AH AH
is a monkey language word.NOTE: All inputs will be capitalized AND will only contain the following letters:
A
,N
,B
, andS
(andX
to denote that the program should terminate, in which case there will be NO output).Sample Input
Sample Output
Explanation of Sample Output
ANA
IS a monkey language word because...A
is a monkey language word. SoANA
is two monkey language words (theA
s) separated by anN
(follows rule #1).BS
IS NOT a monkey language word because...It is offensiveB
andS
. (Violates rule #2.)AANA
IS NOT a monkey language word because...A
s in a row.N
separating them. Two monkey language words must be separated by anN
for it to also be a monkey language word. (Violates rule #1.)BBANASS
IS a monkey language word because...ANA
is two monkey langauge words separated by anN
(follows rule #1).B
andS
surroundANA
, which is a monkey language word (follows rule #2).B
andS
surroundBANAS
, which we already discovered is a monkey language word (follows rule #2).BANASNANANA
IS a monkey langauge word because...ANA
is two monkey language words separated by anN
(follows rule #1).B
andS
surroundANA
, which is a monkey language word (follows rule #2).BANAS
andANANA
are both monkey language words and they are separated by anN
, so it is valid (follows rule #1).ANBANANAS
IS a monkey language word because...A
is a monkey language word according to the question's description.BANANAS
is a monkey language word because theB
and theS
surroundANANA
, which is a monkey language word.ANANA
is a monkey language word since it is just threeA
s (andA
is a monkey language word) separated by anN
(follows rule #1).A
andBANANAS
are both monkey language words and they are separated by anN
(follows rule #1.)BANANANANANANBANANANANANBANANASNANANANBANANASNANANANSS
IS NOT a monkey language word because...NSS
, so theN
is not followed by a monkey langauge word (SS
is not a monkey langauge word for obvious reasons. It literally violates rule #2 and there are noA
s).SAB
IS NOT a monkey language word because...S
andB
are in the wrong order. TheB
must go first. (Violates rule #2.)NOTE: Words like
ANA
are STILL monkey language words even though there are noB
s orS
s. Since there are noB
s orS
s, rule #2 is automatically followed.This is the same for words like
BAS
, which is also a monkey language word even though there are noN
s. Since there are noN
s, rule #1 is automatically followed.Harder than it looks but easier than you think! Fun question!
Would've preferred more sample inputs and outputs...
To anyone who might be reading this: the input is always uppercase, and it can also be empty
i think it's hard to study the monkey word :))
If these are actually monkey words, then BANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANS is a monkey word
That's not a monkey word. Your word ends in "ANANAS" which is invalid. As stated in the question, a monkey language word containing the letter
N
must be preceded and followed by another monkey word. The lastN
is preceded by a monkey language word, but not followed by a monkey language word. All I have to say to you isBANANANANANANBANANANANANBANANASNANANANBANANASNANANANSS
.can someone please help explain/guide me on what's wrong with my code? am i missing an edgecase?
https://dmoj.ca/src/5992485
never mind i found another approach to it
i kept getting the 3rd and 4th case wrong, can someone tell me why I am getting it wrong.
Try the test case
BANANASNBANANAS
, output should beYES
as it is two monkey-language words separated byN
.I'd have thought monkey language would include "EEE EEE" and "AHH AHH". Well, who am I to judge.
Edit: (This is a joke to that one guy)
AA is not a monkey language word.
Also, the largest word in the input is 21 characters long (not including newline).
is BAS a monkey language word?
Think so.
According to CCC test data, blank words and words like "BS" are not monkey language words.
This comment is hidden due to too much negative feedback. Show it anyway.
We take official problem statements from the CCC. Unless there are significant issues with the problem statement, we don't change it.
The problem statement gives a clear input and output specification, even if it doesn't exist as a heading so I do not see the problem.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
Aren't all letters uppercase though? I don't even think there is a case where they're lowercase.
Is "BBBBASSSS" a monkey word?
Yes
Is BANASSNBBANAS a monkey word?
No
I keep getting WA on the last case. Can anyone give me a hint as to what I am doing wrong?
Try inputting "BANSA" into your program. It should output "NO" because the B and S are not separated by a monkey word.
Thank you for spotting my error.
ANABANANAS is a monkey word ??
No, because the two monkey words ('ANA' and 'BANANAS') aren't separated by an 'N'.
Is BANANASNBANANAS a monkey language word?
should be since it's a monkey-language word (BANANAS) followed by N, then by another monkey-language word.
Is BBANANASS a monkey language word?
Yes because it is a 'B' followed by a monkey language word ("BANANAS") and followed by 'S'
Is ANAANA a monkey language word?If not why?
No, since the two A words
ANA
do not have anN
between themThis comment is hidden due to too much negative feedback. Show it anyway.
You may now use
System.exit
; I've patched it to work.Just tell people to use return;
We block
System.exit
for security reasons.On the other hand, you could always use C++ and
std::exit
.For Java, you could just use return to exit the main method, which will terminate the program
This comment is hidden due to too much negative feedback. Show it anyway.
No, they are not monkey language words.