728x90
1. 기본
PS를 할 때 기본적으로 사용되는 입출력이다.
# 입력
# str, 문자열이 그대로 출력
a = input()
# int, 문자열을 정수형으로 변경
a = int(input())
# list, 문자열을 문자(char) 리스트로 변경
a = list(input())
# list, 문자열을 공백으로 구분하여 문자열(str) 리스트로 변경
a = input().split()
# list, 문자열을 공백을 구분하여 정수형 리스트로 변경
a = list(map(int, input().split))
# 복수 할당(공백을 구분하여 각각의 정수를 할당)
a, b, c = map(int, input().split())
# 출력
# 기본 출력
print(a)
# 배열을 "주어진 문자열"로 구분하여 합친 문자열로 출력
print("주어진 문자열".join(a))
2. 빠른 입출력
시간초과를 방지하기 위한 빠른 입출력이다.
import sys
# 빠른 입력, 아래 변수를 선언하고 기본 입력과 똑같이 사용(개행 문자 제거를 유의해야 함)
input = sys.stdin.readline
a = input()
# str
a = input()
# int
a = int(input())
# list(str)
a = list(input().rstrip().split())
# list(char)
a = list(input().rstrip())
# 빠른 출력, 아래 변수를 선언하되, c언어와 비슷한 출력 문법 사용(개행이 없기에 \n 추가 필요
print = sys.stdout.write
print("%s\n" % "hello")
print("%d\n" % 37)
728x90
'PS (Problem Solving)' 카테고리의 다른 글
[BOJ, Python] 10026 - 적록색약 ( with DFS ) (0) | 2022.09.08 |
---|---|
[BOJ, Swift] 1021 - 회전하는 큐 ( with 덱(Dequeue) ) (0) | 2022.08.13 |
[BOJ, Python] 람다(lambda)를 활용한 리스트 정렬 (0) | 2022.07.24 |
[BOJ, Swift] 18258 - 큐 2 (0) | 2022.07.22 |
[BOJ, Swift] 1932 - 정수 삼각형 (0) | 2022.05.08 |