50135. String and Integer

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

Task Description

Write a program to convert between a string and an array of 64-bit integers. Note that the first character of the string should appear in the most significant bits of the the first element of the array. Also note that you need to place the trailing '\0' into the integer, as shown in the following figure.

Every character has 8 bits, so we put 8 consecutive characters into a 64-bit integer starting from the most significant byte (MSB). You may need more than one integer for storing a long string. If the characters do not fill the entire 64 bits, you should set the remaining bits to 0. The following is an example showing the extra 0 bits.

string to integer arraystring to integer array

You also have to do the reverse. That is, given an array of 64-bit integers, you have to generate a string by extracting each byte of the 64-bit integers. The string ends when you have a byte of 0, which is also the character ‘\0’.

integer array to stringinteger array to string

Note that you have to use long long variables to store 64-bit integers, and use “%lld” in scanf() and printf(). We also suggest that you use scanf(“%s”) to read the input string.

Input Format

The first line has an integer task type $T$. If $T$ is 0 then you convert a string into an integer array. If $T$ is 1 then you convert an integer array into a string. If $T$ is 0 the second line is a string $S$. If $T$ is 1 the second line has the size of the array size $N$, and the each of the following $N$ lines has one 64-bit integer for the array. Note that the characters we use in this task are all printable ASCII code and wihtout space.

  • $0 \lt length\ of\ S \lt 100000$
  • $0 \lt N \lt 12500$

Output Format

If $T$ is 0 the output is the array of 64-bit integers, with one line containing one integer. If $T$ is 1 the output is a string.

Subtasks

  • 10 points: $T$ is 0 and $S$ has exactly 7 characters (not including the ending ‘\0’).
  • 40 points: $T$ is 0 and $S$ is not necessarily 7.
  • 10 points: $T$ is 1, the size of the integer array is 1, and only the least significant byte of that integer is 0. That is, the string has exactly 7 characters.
  • 40 points: $T$ is 1, and there are arbitrary number of characters.

Sample Input 1

0
program

Sample Output 1

8102661169684245760

Sample Input 2

0
coding-is-living

Sample Output 2

7165055936156347753
8299408888527679079
0

Sample Input 3

1
1
8102661169684245760

Sample Output 3

program

Sample Input 4

1
4
6424453515915647277
5278620438910559353
6084160122668532545
4846228539649687552

Sample Output 4

Y(>o<)Y-IAmReadyToGetACACAC...

Sample for subtask 1 ~ 4

Inside the testdata.

Discussion