CCC '05 J5 - Bananas

View as PDF

Submit solution

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

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
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

Comments


  • -6
    Subway_Man  commented on June 14, 2020, 6:47 p.m.

    This comment is hidden due to too much negative feedback. Click here to view it.


    • -1
      c  commented on June 14, 2020, 9:19 p.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.


      • -2
        Subway_Man  commented on June 15, 2020, 2:51 a.m.

        It is not specified whether the input is all capitalised or not. For people reading this, upon testing, all letters seem to be UPPERCASE.


        • -1
          injust  commented on June 15, 2020, 11:58 a.m.

          It's irrelevant if the characters are uppercase letters or otherwise.


        • -1
          AlanL  commented on June 15, 2020, 11:10 a.m.

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


  • 2
    noYou  commented on Feb. 25, 2020, 7:27 p.m.

    is BASNBAS a word?


    • 2
      willis  commented on May 12, 2020, 5:39 p.m.

      Yes


  • -3
    Bwaziken  commented on Feb. 11, 2020, 12:30 a.m. edited

    I get WA on cases 2-4 for some not sure what I'm missing any ideas? EDIT: nvm I realized that after reading comments and rereading the question I have concluded that I have missed a vital word of the question


  • 1
    David1425  commented on Feb. 9, 2020, 3:57 p.m.

    Is "BBBBASSSS" a monkey word?


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

      Yes


  • -1
    aaronw1091  commented on Feb. 8, 2020, 7:03 p.m.

    I keep WA-ing on cases 3 and 4, what am I doing wrong?


  • 0
    Togohogo1  commented on Dec. 23, 2019, 9:07 p.m.

    Is BANASSNBBANAS a monkey word?


  • 2
    4fecta  commented on June 8, 2019, 3:08 p.m.

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


    • 5
      lookcook  commented on June 8, 2019, 4: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.


      • 3
        4fecta  commented on June 8, 2019, 5:14 p.m.

        Thank you for spotting my error.


  • 0
    anasschoukri2  commented on Aug. 22, 2017, 11:05 a.m.

    ANABANANAS is a monkey word ??


    • 1
      aeternalis1  commented on Aug. 22, 2017, 12:20 p.m. edited

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


  • -1
    susheelk  commented on Feb. 15, 2017, 5:50 p.m. edited

    Is BANANASNBANANAS a monkey language word?


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

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


  • -1
    TheKrishnan  commented on Feb. 9, 2017, 3:37 p.m.

    Is BBANANASS a monkey language word?


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

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


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

    Is ANAANA a monkey language word?If not why?


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

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


  • -20
    bobbotboy  commented on June 13, 2015, 11:31 p.m. edit 2

    This comment is hidden due to too much negative feedback. Click here to view it.


    • -9
      Jeffmagma  commented on Nov. 22, 2016, 7:32 p.m.

      This comment is hidden due to too much negative feedback. Click here to view it.


    • -7
      HowAboutNo  commented on Feb. 16, 2016, 8:22 p.m.

      This comment is hidden due to too much negative feedback. Click here to view it.


  • -6
    Eli  commented on Feb. 2, 2015, 6:50 p.m.

    This comment is hidden due to too much negative feedback. Click here to view it.


    • 0
      Xyene  commented on Feb. 27, 2015, 12:01 p.m.

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


      • 11
        BMP  commented on Feb. 27, 2015, 5:35 p.m.

        Just tell people to use return;


    • 1
      FatalEagle  commented on Feb. 2, 2015, 7:23 p.m.

      We block System.exit for security reasons.

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


      • 8
        Sentient  commented on Feb. 2, 2015, 7:46 p.m.

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


  • -7
    Yuting9  commented on Nov. 19, 2014, 8:12 p.m.

    This comment is hidden due to too much negative feedback. Click here to view it.


    • 3
      FatalEagle  commented on Nov. 19, 2014, 9:17 p.m.

      No, they are not monkey language words.


      • -10
        xxsc  commented on Oct. 23, 2017, 7:53 p.m. edited

        This comment is hidden due to too much negative feedback. Click here to view it.


      • -7
        xxsc  commented on Oct. 23, 2017, 7:47 p.m. edit 2

        This comment is hidden due to too much negative feedback. Click here to view it.