Rotate Array In-Place

Back to General discussions forum

Yevgeny Romanov     2023-11-11 16:11:23
User avatar

Hello. Could you add the expected result please? As in previous tasks. Thank you.

Rodion (admin)     2023-11-11 16:31:14
User avatar

Yevgeny, Hi!

Well, perhaps it is good idea, thanks. I've just tried to add it in two places:

  • in the example input data (it is going to be ignored anyway)
  • when "wrong answer for N, K" is returned

Please tell if it helps!

Yevgeny Romanov     2023-11-11 17:13:30
User avatar

hmm. that helped. but i'm not sure if the task is working correctly.

input:

5 1

1 2 3 4 5

output:

2 3 4 5 1

the result is "wrong"(

your explanation:

Wrong result for N=5 K=1: for [49 52 93 60 40] result should be [52 ...]

if you need i will send you my code

gardengnome     2023-11-11 17:31:06
User avatar

Hi, you don't actually rotate the array, you just print its elements in a different order. That's not quite the same thing.

TestUser     2023-11-11 17:38:14
User avatar

(upd, it's me, admin again, just was testing your code and forgot to re-login)

Ah, I checked your code and probably I see there is small misunderstanding.

These BASIC problems do not require you to output anything. Specifically in this problem you need to modify array in your code, or rather in rotate subroutine.

When you submit your code, the checker adds its own lines in front of yours, like this:

  • checker sets array A to some values (e.g. starting with 49 52 93... as in your example)
  • then your subroutine rotate is called
  • now checker tests that A(0) should be 52 and so on
  • at last checker verifies that your code haven't created any new arrays (to verify that all operations were done inside the A array, that is "in place").

So you see, these BASIC problems are not needed to teach people BASIC (probably no one will need it) but to have the simplified language where it is easy to check (for checker) that you invented correct algorithm.

So to conclude, checker doesn't look at what your code prints. Instead it checks contents of the array after your code runs.

Yevgeny Romanov     2023-11-11 17:49:02
User avatar

Got it. Thank you all.

Please login and solve 5 problems to be able to post at forum