본문 바로가기
Python/Python

input() 대신 sys.stdin.readline() 사용

by Sondho 2020. 4. 13.

map, input().split()을 사용하여 값을 입력받기

for i in range(1, (int(input())+1)):
    x = map(int, input().split())
    print(sum(x))


# 실행결과
1
100 200
300

 

 

sys.stdin.readline().split()을 사용하여 값을 입력받기

import sys

for i in range(1, (int(input())+1)):
    x = map(int, sys.stdin.readline().split())
    print(sum(x))


# 실행결과
1
100 200
300

 

 

 

 

관련 문제 : https://www.acmicpc.net/problem/15552

 

15552번: 빠른 A+B

첫 줄에 테스트케이스의 개수 T가 주어진다. T는 최대 1,000,000이다. 다음 T줄에는 각각 두 정수 A와 B가 주어진다. A와 B는 1 이상, 1,000 이하이다.

www.acmicpc.net

 

댓글