50067. Walk in a File

I'm a slow walker, but I never walk backwards.

Task Description

Write a program to read and follow instructions in a binary file. An instruction has eight bytes. The first four bytes is an integer code indicating instruction type and the next four bytes are the parameter of this instruction.

The instruction types are as follows.

  • If the type is 0, print the parameter as an integer and read the next instruction after this instruction.
  • If the type is 1, print the parameter as four characters and read the next instruction after this instruction.
  • If the type is 2, print the string after the parameter and read the next instruction after the end of the string. That is, you need to print all characters after the parameter until \0 appears.
  • If the type is 3, use the position of the first byte of this instruction as a base and the parameter (as an integer) as an offset, to seek within the file and read the next instruction at the position you seek.
  • If the type is 4, go to the relative position from the beginning of the file. The offset is given as the parameter of this instruction.
  • If the type is 5, go to the relative position from the end of the file. The offset is given as the parameter of this instruction.
  • For all other types, print a string Seek end and stop the program.

We read the first instruction at the start of a file.

Input Format

A string without space is the file name (length < 16). This target file size is much bigger than memory so that you can’t read all file into memory.

Output Format

Print some strings or characters or integers in one line.

Sample Input

1
p10155-sample.dat

download p10155-sample.dat

Sample Output

1
765 Haruka Miki    Seek end

Hint

Subtask 0 has all kind of instruction type.

Subtask 1 has type 0,2,3.

Subtask 2 has type 1,4,5.

Subtask 3 has all kind of instruction type.

Discussion