50103. File Mirroring and Shifting

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

Write a program to mirror and shift a binary file.

Problem Description

Given the names of an input binary file of $L$ bytes, the name of an output file and an integer $N$, mirror the file first, then shift the left $N$ bytes and write the contents to the output binary file. For example, if a file consists of 00010011 01011100 00100110 11000101, after mirroring, it will be 10100011 01100100 00111010 11001000. Then we shift left $3$ bytes, it will be 11001000 10100011 01100100 00111010.

Subtasks

  • 10 points: The whole file can be read into memory and $N$ is $0$ (file length < 4096 Bytes).
  • 20 points: The whole file can be read into memory and $N$ is between $0$ and $L - 1$ (file length < 4096 Bytes).
  • 70 points: The file will be too large to read into memory.

Input Format

The input contains only one test case. There are two strings in the first line. The first string is the name of the input file and the second string is the name of the output file. The second line of the input is N. The name of the files have no more than 16 characters.

Output Format

Write a binary file with given output file name.

Sample Input 0 (stdin)

p10190-0-in.dat

0-in.dat 0-out.dat
0

(binary file contents)

00010011 01011100 00100110 11000101

Sample Output 0 (binary file)

p10190-0-out.dat

(binary file contents)

10100011 01100100 00111010 11001000

Sample Input 1 (stdin)

p10190-1-in.dat

1-in.dat 1-out.dat
3

(binary file contents)

00010011 01011100 00100110 11000101

Sample Output 1 (binary file)

p10190-1-out.dat

(binary file contents)

11001000 10100011 01100100 00111010

Sample Input 2 (stdin)

p10190-2-in.dat

2-in.dat 2-out.dat
27

Sample Output 2 (binary file)

p10190-2-out.dat

Discussion