CCC '05 J3 - Returning Home

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Problem type
Canadian Computing Competition: 2005 Stage 1, Junior #3

Jane's family has just moved to a new city and today is her first day of school. She has a list of instructions for walking from her home to the school. Each instruction describes a turn she must make. For example, the list

R
QUEEN
R
FOURTH
R
SCHOOL

means that she must turn right onto Queen Street, then turn right onto Fourth Street, then finally turn right into the school. Your task is to write a computer program which will create instructions for walking in the opposite direction: from her school to her home.

The input and output for your program will be formatted like the samples below. You may assume that Jane's list contains at least two but at most five instructions, and you may assume that each line contains at most 10 characters, all of them capital letters. The last instruction will always be a turn into the SCHOOL.

Sample Input 1

R
QUEEN
R
FOURTH
R
SCHOOL

Sample Output 1

Turn LEFT onto FOURTH street.
Turn LEFT onto QUEEN street.
Turn LEFT into your HOME.

Sample Input 2

L
MAIN
R
SCHOOL

Sample Output 2

Turn LEFT onto MAIN street.
Turn RIGHT into your HOME.

Comments


  • 0
    701030474  commented on March 13, 2025, 4:23 p.m.

    there are 2 ways to do this, the first is by getting 2 lists and reversing the turns list and reversing the location list (all except for school, it needs to be last) then you iterate through the turns list to flip R and L(flipped and reversed). The you want to iterate through the reversed locations list and using an f string and indexes, put it all together. the second way is more complicated, you use one big list and by iterating through the big list reverse everything except for school, then you want to flip the L and Rs and then loop through again to print out the answer


  • 0
    Crakxinator  commented on Feb. 16, 2025, 4:28 a.m.

    What is wrong with my code? I get WA'd on 2nd test case.


    • 1
      4EVr_Working  commented on Feb. 17, 2025, 1:14 a.m. edit 4

      Why are you printing m[i-1]? If you are trying to print the last element in an index, just type m[-1] instead.

      Basically, your code is getting WA in the second test case since m[i-1] will always print the direction of the third last element in your list m. So if it doesn't happen to be the same as the direction to turn home. You get WA.

      Consider this case:

      R
      FOURTH
      R
      FIFTH
      L
      SIXTH
      R
      SCHOOL

      Output should be:

      Turn LEFT onto SIXTH street.
      Turn RIGHT onto FIFTH street.
      Turn LEFT onto FOURTH street.
      Turn LEFT into your HOME.

      Your code will fail this case because for the last direction, you are always printing the same direction two directions ago. (In this case, you will print Turn RIGHT into your Home. instead of LEFT. This is because two directions ago, you had to turn RIGHT at Fifth Street. So it just prints the same direction as that and gets WA.)

      HOPE THIS HELPS :)))


      • 0
        701030474  commented on March 13, 2025, 4:25 p.m.

        this helped a lot, i needed a longer sample to confirm if my strategy was correct, thanks


  • 0
    BlackHat42  commented on Dec. 28, 2024, 1:08 a.m.

    I forgot to add street onto my output, spent 30 min trying to see if my math was wrong. I somehow still remembered the period at the end though:-(


  • 2
    YeetusPoteetus2  commented on Jan. 30, 2023, 12:53 p.m.

    my program works when I am testing it with the samples, however when I submit it, it does not fully print the answer. instead it does this "Test case #1:
    WA [0.030s, 10.16 MB] (0/10)

    Your output (clipped) Turn RIGHT onto D street. Turn RIGHT onto C street. Turn RIGHT o

    I do not understand what happened.


    • 2
      dnialh_  commented on Jan. 31, 2023, 7:30 a.m.

      DMOJ only shows a clipped version of your output on the site (to make sure nothing major is going wrong). The full version of your output is being seen on the server (and is being judges as WA).


  • -2
    BaconBest  commented on May 16, 2021, 12:58 a.m.

    how do you make the street names flip over?


    • 7
      Azdera  commented on July 9, 2021, 12:32 a.m.

      Check if they are L or R and switch correspondingly.


  • 3
    Arihan10  commented on Jan. 18, 2019, 2:24 a.m. edit 2

    Shouldn't Sample Input 2 be:

    Turn RIGHT onto MAIN street.
    Turn LEFT into your HOME.

    Since R = L and L = R?

    EDIT: I realized my mistake.


    • -67
      magicalsoup  commented on Jan. 18, 2019, 2:32 a.m.

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


      • 13
        Haoyun  commented on Jan. 18, 2022, 6:42 p.m.

        Don't be such a meany


      • 25
        Arihan10  commented on Jan. 18, 2019, 2:50 p.m.

        No, sorry, I now realize that the Sample is correct.


  • -11
    raggarwal  commented on Nov. 26, 2014, 3:34 p.m.

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


    • 37
      FatalEagle  commented on Nov. 26, 2014, 6:55 p.m.

      It will always end with SCHOOL.