CCC '02 J2 - AmeriCanadian

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 256M

Problem type
Canadian Computing Competition: 2002 Stage 1, Junior #2

Americans spell differently from Canadians. Americans write neighbor and color while Canadians write neighbour and colour. Write a program to help Americans translate to Canadian.

Your program should interact with the user in the following way. The user should type a word (not to exceed 64 letters) and if the word appears to use American spelling, the program should echo the Canadian spelling for the same word. If the word does not appear to use American spelling, it should be output without change. When the user types quit! the program should terminate.

The rules for detecting American spelling are quite naive: If the word has more than four letters and has a suffix consisting of a consonant followed by or, you may assume it is an American spelling, and that the equivalent Canadian spelling replaces the or by our. Note: you should treat the letter y as a vowel.

Sample Input

color
for
taylor
quit!

Sample Output

colour
for
taylour

Comments


  • -6
    ahora240  commented on April 6, 2024, 2:53 p.m. edit 2

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


    • 0
      jrkws  commented on May 18, 2024, 9:44 p.m.

      you have to ensure the letter before 'or' is a consonant


    • -4
      rfasta  commented on May 16, 2024, 1:42 a.m.

      pls make sure u goto the discord server to ask for help instead of commenting.


  • 0
    JuanJCM  commented on March 28, 2024, 1:11 a.m.

    For anyone struggling there's something that (I believe) is not clearly stated which is that for the rule to apply (change "or" to "our") the "or" must be at the END of the sentence


  • -6
    ayazzy  commented on Jan. 25, 2024, 3:55 a.m. edited

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


    • 0
      jrkws  commented on May 18, 2024, 9:45 p.m. edit 2

      I thought y wasn't a vowel... edit: nevermind I just read that it said to treat y as a vowel


    • -4
      Weifeng_Wang  commented on Feb. 21, 2024, 2:31 a.m. edited
      def is_vowel(char):
          return char in "aeiouy"
      def to_canadian(word):
          if len(word) > 4 and word[-2:] == "or" and not is_vowel(word[-3]):
              return word[:-2] + "our"
          return word
      def main():
          while True:
              word = input()
              if word == "quit!":
                  break
              print(to_canadian(word))
      
      main()
      

    • 0
      anjaneya  commented on Feb. 12, 2024, 7:19 a.m.

      i am also confused does f in for count as consonant? are there anymore recommended test cases?


    • 0
      b_nary  commented on Jan. 25, 2024, 4:52 a.m.

      Make sure that "or" must appear at the middle of the word (i.e suffix). Currently your program replaces "or" with "our" even if "or" appears somewhere else like in the middle, but it must appear at the end


  • 4
    Gilgamesh_101  commented on Sept. 19, 2022, 6:18 a.m.

    I had mine first try, but was printing 'quit!' along side my output

    don't do that! I was very confused.


  • 0
    Berton  commented on Aug. 25, 2022, 2:22 a.m.

    Only 1 test case???


  • 3
    ducws  commented on June 19, 2022, 9:49 a.m. edit 2

    instructor -> instructour (I'm not English native and based on my knowledge it doesn't exist 'instructour' word) but my answer is still accepted. If anyone can explain it that would be great. Thanks


    • 4
      Tofer_G  commented on June 20, 2022, 3:22 p.m.

      Instructour is not actually a word.

      "The rules for detecting American spelling are quite naïve:"

      The program does not actually detect if words are real words. After all, you could potentially have a word 64 letters long. It is just detecting a sequence, and making the changes. So in this instance, correct answers are not necessarily real words. I hope that make sense for you.

      Now if you see this, try and answer my question below please :D


  • 5
    breakWood  commented on Jan. 8, 2022, 9:21 a.m.

    Be careful, vowel+or still no need to change, like floor...


  • -2
    MakerKaren  commented on Dec. 24, 2021, 7:05 p.m. edited

    For those that know American vs Canadian spellings, neighbor should become neighbour, but instructor should not become instructour. But according to the given rules, it should. Given the spelling/structure of those words, I'm not sure how to tell the program how to tell the difference.


    • 5
      Spitfire720  commented on Dec. 24, 2021, 8:10 p.m.

      I think you're too tripped over how American spelling really is. Pretend that this is the new way of American spelling; since it's a 3 pointer, they're not looking for anything complicated.


  • 6
    Harryg33107  commented on Aug. 28, 2019, 4:32 p.m.

    Can I assume the input is all lowercase letters?


  • -3
    Charles232  commented on Jan. 18, 2019, 2:19 a.m.

    What if the word has 2 "or"s???


    • 9
      magicalsoup  commented on Jan. 18, 2019, 2:34 a.m.

      it wont happen, according to the ccc test cases, but i believe the problem statement is clear enough