Update appNew update is available. Click here to update.

Read N Characters Given Read4 ll - Call Multiple Times

Last Updated: 18 Mar, 2021
Difficulty: Moderate

PROBLEM STATEMENT

Try Problem

Ninja has been given a file ‘FILE’ that can be read using a given method, ‘READ4’. Ninja has to implement a method ‘READ’, which reads ’N’ characters from the ‘FILE’ using the ‘READ4’ method.

How ‘READ4’ and ‘READ’ method’s work:

‘READ4(char ‘BUFFER[]’)’

 1) It reads 4 characters at a time from the ‘FILE’.
 2) The return value of the ‘READ4’ method is the actual number of characters read.
 3) For example, if in a ‘FILE’ only three characters are remaining, then it returns 3.

‘READ(char ‘BUFFER[]’, int ‘N’)’

 1) ‘N’ represents the number of characters to be read from ‘FILE’.
 2) In this method, you have to store your result in ‘BUFFER’.
 3) In this method, you have to return the number of characters read from ‘FILE’.

Note: The method ‘READ’ may be called multiple times.

For example:

‘FILE’ = “abcdef”

Initially file pointer ‘FP’ points to ‘a’.
‘READ4(BUFFER) returns 4 and ‘BUFFER’ contains “abcd”, Now the ‘FP’ points to ‘e’.
‘READ4(BUFFER) returns 2 and ‘BUFFER’ contains “ef”, Now the ‘FP’ points to the end of the ‘FILE’.
Input Format
The first line of input contains an integer ‘T’ which denotes the number of test cases or queries to be run. Then the test cases follow.

The first line of each test case contains a string ‘FILE’ which represents a file that Ninja has to read.

The next line of each test case contains an integer ‘Q’, representing how many times the ‘READ’ function is called.

The next lines of each test case contain ‘Q’ space-separated integers which represent how many characters are to be read from the ‘FILE’.
Output Format :
For each test case, print the number of characters and actual characters which are read by Ninja from the ‘FILE’. 

Print the output of each test case in a separate line.

Note:

You do not need to print anything; it has already been taken care 
of. Just implement the given function.
Constraints:
1 <= ‘T’ <= 100
1 <= |’FILE’| <= 5000
‘FILE[i]’ = {‘a’ to ‘z’}

Where ‘T’ denotes the total number of test cases, ‘FILE’  represents the file that Ninja has to read, and |’FILE’| represents the length of the ‘FILE’.

Time Limit: 1 second