포스트

[Python] Baekjun No. 15552 - Fast A+B

We have compiled a solution for quickly handling multi-line input using sys.stdin.readline() in Python.

한국어 원문은 여기에서 볼 수 있습니다.
[Python] Baekjun No. 15552 - Fast A+B

BaekJoon 15552

Solution

1
2
3
4
5
6
7
import sys

n = int(input())

for i in range(n):
    a, b = map(int, sys.stdin.readline().split())
    print(a+b)

많은 수의 입력이 있을 때 in Python

  • In Python, it is better than the previously used input().
  • Better to use readline()

    readline()

  • Faster input than input()
  • Use: import sys
  • Default: a = sys.stdin.readline() -> Comes as a string containing \n
  • Remove newline (\n): a = sys.stdin.readline().rstrip()
  • Enter multiple values: a, b = map(int, sys.stdin.readline().split())