0

Objective: to have one integer per line in the output.

Description: I have to use atexit, io, sys. I am attempting to get better IO performance with Python, then the standard input() and print() functions.

# import libraries for input/ output handling
# on generic level
import atexit, io, sys
 
 
# A stream implementation using an in-memory bytes 
# buffer. It inherits BufferedIOBase.
buffer = io.BytesIO()
sys.stdout = buffer
 
# # print via here
@atexit.register
def write():
    sys.__stdout__.write(str(buffer.getvalue()))
n=input()
for i in range(int(n)):
    r=input()
    A, B = [int(c) for c in r.split()]
    count_e_i, count_o_i, count_e_j, count_o_j = 0, 0, 0, 0    
 
    for i in range(1, A + 1):
        if (i) % 2 == 0:
            count_e_i += 1
        else:
            count_o_i += 1
 
    for j in range(1, B + 1):
        if (j) % 2 == 0:
            count_e_j += 1
        else:
            count_o_j += 1
 
    sys.stdout.write((str((count_e_i * count_e_j) + (count_o_i * count_o_j))+"\n").encode('utf-8'))

I enter in the following information:

enter image description here

I was expecting the following results:

1
3
12
36
Student
  • 1,197
  • 4
  • 22
  • 39
  • I can't recreate the problem that you are having. Could you give the procedure on what you did? – A random coder Dec 07 '20 at 19:42
  • Does this answer your question? [Convert bytes to a string](https://stackoverflow.com/questions/606191/convert-bytes-to-a-string) – mkrieger1 Dec 07 '20 at 19:49
  • I ran the program. Entered in the number 4, hit enter. Entered in the numbers 1 1, hit enter. Entered in the numbers 2 3, hit enter. Entered in the numbers 4 6, hit enter. Entered in the numbers 8 9, hit enter. – Student Dec 07 '20 at 19:54

0 Answers0