The API: int read4(char *buf) reads 4 characters at a time from a file.
The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the file.
By using the read4 API, implement the function int read(char *buf, int n) that reads n characters from the file.
Note:
The read function may be called multiple times.
解法1:
这题其实针对的是在I中的解法里的一个问题,就是多读的buf会被扔掉。
这里因为要call multiple times,那么不能扔掉多读的,而是要存起来。
存起来的办法就是建一个queue,先读queue里的数,如果有多的就放回到queue里。
C++
Java