Python3 standard input for competitive programming

Overview

This is a standard input memo that is often used for Python 3 competition pros.

I've put them together in one code with comments so you don't get lost when referencing.

code


'''
Summary of how to receive standard input
'''

#___If you want the strings and numbers as they are___#
#Character string line by line
s = input()

#2 strings per line
s, t = input().split()

#Integer line by line
s = int(input())

#Integer 1 line 2
n, m = map(int, input().split())


#___If you want a list___#
#List string 1 line
a = input().split()

#List integer 1 line
a = list(map(int, input().split()))

#List string n is the specified line
a = [input() for i in range(n)]

#List Integer n is the specified row
a = [int(input()) for i in range(n)]

#___If you want a two-dimensional array___#
#Two-dimensional array Character string n is specified line Multiple matrices separated by spaces
a = [input().split() for l in range(n)]

Recommended Posts

Python3 standard input for competitive programming
[Python] Standard input
[Competitive programming] [Python3] Required knowledge, for myself
Atcoder standard input set for beginners (python)
Competitive programming diary python 20201213
Competitive programming diary python 20201220
Competitive programming with python
[Python] About standard input
Competitive programming diary python
[Python3] Standard input [Cheat sheet]
Python3 standard input (competition pro)
Standard input / summary / python, ruby
Receiving standard input tips @ python
Python Competitive Programming Site Summary
[For AtCoder] Standard input memo
Matrix representation with Python standard input
[Python] Building an environment for competitive programming with Atom (input () can be used!) [Mac]
Competitive programming, coding test template: Python3
[For beginners] Summary of standard input in Python (with explanation)
Notes for Python file input / output
[For beginners of competitive pros] Three input methods to remember when starting competitive programming in Python
Input / output method of values from standard input in competitive programming, etc.
Python Paiza-Various skill checks and standard input
Competitive programming with python Local environment settings
"Python AI programming" starting from 0 for windows
Python3 standard input I tried to summarize
[Python] Add comments to standard input files
2016-10-30 else for Python3> for:
python [for myself]
Python programming note
Tips (input / output) that you should know when programming competitive programming with Python2
Programming in python
Standard input summary
I made a competitive programming glossary with Python
I tried python programming for the first time.
Program to search all permutations (for competitive programming)
Introduction to Programming (Python) TA Tendency for beginners
Python: Use zipfile to unzip from standard input
Competitive Pro with Python and VSCode-Simplification of standard input and automation of sample case judgment-
Get all standard inputs used in paiza and competitive programming with int (python)
About Python for loops
Key input in Python
I tried competitive programming
Python basics ② for statement
3. 3. AI programming with Python
Key input that does not wait for key input in Python
Competitive Pro Template (Python)
HoloViews may become the standard for Python visualization tools
Have python parse the json entered from the standard input
About Python, for ~ (range)
python textbook for beginners
Refactoring tools for Python
Python programming with Atom
python input and output
[Python] Change standard input from keyboard to text file
Python audio input / output
Preparing to start "Python machine learning programming" (for macOS)
python for android Toolchain
Kyoto University Python programming practice materials released for free
Memorize Python commentary 4 --Input
Tips you should know when programming competitive programming with Python2