0% found this document useful (0 votes)
5 views6 pages

Tcs 2

Uploaded by

raguljdt.st
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Tcs 2

Uploaded by

raguljdt.st
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 6

Formatting Software

Problem Description

Vivek is developing software that takes a set of numerical instructions, processes them, and formats
them as required.

Vivek is working on a big project, and he asked you to implement a software that takes a set of numerical
information in the form of r x c matrices, processes them, and formats them according to the given
instructions. The instructions consist of multiple lines, with each line containing one or more integer
values. Each integer specifies which matrix should be printed.

For example, if the instructions are like below,

123

which says that you should first print matrix number 4 from the information provided. Then, on the
subsequent lines, you need to print matrices 1, 2, and 3 sequentially.

Given N, representing the number of matrices, and two additional integers r and c representing the
number of rows and columns in each matrix, along with the N matrices provided contiguously over r
lines, and in the decribed format, print the formatted information.

(Refer Examples section for better understanding of the input)

Constraints

1 <= N <= 10
1 <= r, c <= 10

1 <= numbers in the matrix <= 100

1 <= number of matrices in the instructions <= 20

Matrices are numbered from 1 to N; thus, the instructions will include only numbers within this range.
Note that numbers may be repeated.

Input

First line consists of an integer N, denoting the number of matrices

Second line consists of two space separated integers denoting the number of rows and columns in each
matrix.

The next r lines contain the N matrices, each of size r × c, listed sequentially. Each matrix will have
integers separated by spaces, and consecutive matrices will be separated by a space as well.

Remaining lines represent the instructions of how the information should be formatted.

Output

Print the formatted information following the given instructions.

Time Limit (secs)

Examples
Example 1

Input

13

5 4 12 11 19 3 0 15 7 1 2 3 4 5 6 10 9 8 3 60 71

713

245

36

Output

456

3 60 71 5 4 12 0 15 7
11 19 3 1 2 3 4 5 6

0 15 7 10 9 8

123

Explanation

If you split the given data into 1x3 submatrices and print them in the specified format, you will obtain
the output. Let's go over the input processing.

Line 4 i.e. input 5 asks to print matrix number 5. Output 4 5 6 corresponds to this input.

Line 5 i.e. input 7 1 3 asks to print matrices 7, 1 and 3. Output 3 60 71 5 4 12 0 15 7 corresponds to this
input.

Similarly processing line number 6, 7 and 8 of the input, we obtain lines 3, 4 and 5 of the output.

Example 2

Input

23
1 2 3 4 5 6 7 8 9 10 11 12

12 11 10 9 8 7 6 5 4 3 2 1

123

41

23

14

Output

123456789

12 11 10 9 8 7 6 5 4

10 11 12 1 2 3

3 2 1 12 11 10
456789

987654

789

654

1 2 3 10 11 12

12 11 10 3 2 1

Explanation

If you split the given data into 2x3 submatrices and print them in the specified format, you will obtain
the output. Let's go over the input processing.

Line 5 i.e. input 1 2 3 asks to print matrices 1, 2 and 3. Output lines 1 and 2 corresponds to this input.

Line 6 i.e. input 4 1 asks to print matrices 4 and 1. Output lines 3 and 4 corresponds to this input.

Similarly processing line number 7, 8 and 9 of the input, we obtain lines the remaining lines of the
output.

You might also like