## CCC '05 J5 - Bananas

View as PDF

Points: 10
Time limit: 1.0s
Memory limit: 256M

Problem types
##### 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.

1. 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.
2. An A-word is either only the single letter A, or the letter B followed by a monkey language word followed by the letter S.

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-word A followed by the letter N and the monkey language word A.
• The word ANANA is a monkey language word because it is the A-word A followed by the letter N and the monkey language word ANA.
• The word BANANAS is a monkey language word because it is an A-word, since it is the letter B followed by the monkey language word ANANA followed by the letter S.

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

• commented on March 31, 2024, 2:48 p.m.

i think it's hard to study the monkey word :))

• commented on Jan. 5, 2024, 2:55 a.m.

If these are actually monkey words, then BANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANANS is a monkey word

• commented on Jan. 12, 2024, 4:10 a.m.

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 last N is preceded by a monkey language word, but not followed by a monkey language word. All I have to say to you is BANANANANANANBANANANANANBANANASNANANANBANANASNANANANSS.

• commented on Dec. 11, 2023, 2:07 a.m.

can someone please help explain/guide me on what's wrong with my code? am i missing an edgecase?

https://dmoj.ca/src/5992485

• commented on Dec. 11, 2023, 6:48 p.m.

never mind i found another approach to it

• commented on Jan. 2, 2023, 2:52 a.m.

i kept getting the 3rd and 4th case wrong, can someone tell me why I am getting it wrong.

• commented on Jan. 2, 2023, 10:59 p.m.

Try the test case BANANASNBANANAS, output should be YES as it is two monkey-language words separated by N.

• commented on May 17, 2021, 11:20 p.m. edited

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)

• commented on May 17, 2021, 3:32 p.m. edit 2

AA is not a monkey language word.

Also, the largest word in the input is 21 characters long (not including newline).

• commented on Jan. 24, 2021, 7:07 p.m.

is BAS a monkey language word?

• commented on Jan. 25, 2021, 5:07 p.m.

Think so.

• commented on Nov. 26, 2020, 9:50 p.m.

According to CCC test data, blank words and words like "BS" are not monkey language words.

• commented on June 14, 2020, 10:47 p.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on June 15, 2020, 1:19 a.m.

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.

• commented on June 15, 2020, 6:51 a.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on June 15, 2020, 3:58 p.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on June 15, 2020, 3:10 p.m.

Aren't all letters uppercase though? I don't even think there is a case where they're lowercase.

• commented on Feb. 9, 2020, 8:57 p.m.

Is "BBBBASSSS" a monkey word?

• commented on Feb. 9, 2020, 9:08 p.m.

Yes

• commented on Dec. 24, 2019, 2:07 a.m.

Is BANASSNBBANAS a monkey word?

• commented on Dec. 24, 2019, 6:43 p.m. edited

No

• commented on June 8, 2019, 7:08 p.m.

I keep getting WA on the last case. Can anyone give me a hint as to what I am doing wrong?

• commented on June 8, 2019, 8:46 p.m.

Try inputting "BANSA" into your program. It should output "NO" because the B and S are not separated by a monkey word.

• commented on June 8, 2019, 9:14 p.m.

Thank you for spotting my error.

• commented on Aug. 22, 2017, 3:05 p.m.

ANABANANAS is a monkey word ??

• commented on Aug. 22, 2017, 4:20 p.m. edited

No, because the two monkey words ('ANA' and 'BANANAS') aren't separated by an 'N'.

• commented on Feb. 15, 2017, 10:50 p.m. edited

Is BANANASNBANANAS a monkey language word?

• commented on July 7, 2017, 11:47 p.m.

should be since it's a monkey-language word (BANANAS) followed by N, then by another monkey-language word.

• commented on Feb. 9, 2017, 8:37 p.m.

Is BBANANASS a monkey language word?

• commented on Feb. 9, 2017, 9:44 p.m.

Yes because it is a 'B' followed by a monkey language word ("BANANAS") and followed by 'S'

• commented on Jan. 22, 2017, 6:14 p.m.

Is ANAANA a monkey language word?If not why?

• commented on Jan. 22, 2017, 6:47 p.m.

No, since the two A words ANA do not have an N between them

• commented on Feb. 2, 2015, 11:50 p.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Feb. 27, 2015, 5:01 p.m.

You may now use System.exit; I've patched it to work.

• commented on Feb. 27, 2015, 10:35 p.m.

Just tell people to use return;

• commented on Feb. 3, 2015, 12:23 a.m.

We block System.exit for security reasons.

On the other hand, you could always use C++ and std::exit.

• commented on Feb. 3, 2015, 12:46 a.m.

For Java, you could just use return to exit the main method, which will terminate the program

• commented on Nov. 20, 2014, 1:12 a.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Nov. 20, 2014, 2:17 a.m.

No, they are not monkey language words.