[For beginners of competitive pros] Three input methods to remember when starting competitive programming in Python

He made his debut in Python on August 22, 2020 in competitive programming. Participating was AtCoder, which comes to mind when it comes to competitive programming in Japan.

Before I started learning Python, I actually registered as a member and was ready to start. When you solved the past questions? ?? I kept that I gently registered with AtCoder in the storage room of my heart.

Why couldn't you work on competitive programming?

The reason is simple.

** Because I stumbled on the standard input part in Python in the first place orz **

Of course, I had read through the Python introductory book by then, so I knew that I should use input for the input method. However, my understanding of input was overwhelmingly insufficient.

Speaking of input handled in the Python Primer

Speaking of input, it will appear in Chapters 1 and 2 after setting up the environment in the Python Primer. I will refrain from the sample code, but the sample code that produces such an output is posted.

$:Enter the text! : ○○
$:Hello! ○○

Even if you proceed to the following chapters, you tend to study other contents rather than learning various ways to use input. As a result, even though I knew about input, I didn't understand it. I challenged it to competitive programming and was made aware of it. In a blink of an eye, my head froze and I closed the AtCoder tab ...

How to use 3 inputs to remember by solving past questions

Meanwhile, by increasing the chances of writing code properly, I was motivated to try competitive programming again, so I returned to AtCoder again.

** "Even if I don't know this time, I'll try to google without freezing." **

With that in mind, when I thoroughly investigated the input method, I was able to clear the A and B problems. The C problem struggles with computational complexity O (N ^ 2) and suffers from a "TLE" wall that exceeds the time limit ...

Meanwhile, ** It turned out that the "standard input" of the introduction part that I stumbled upon and threw out was mainly summarized in the following three. ** **

Enter one integer

a = int(input())

A pattern in which one integer is entered in one line. The B problem of AtCoder Beginner Contest 176 on August 22, 2020 was this pattern. However, there are few cases where only one integer is entered, and there are many cases where the questions are basically combined with the two patterns described later.

Enter multiple integers

a,b,c = map(int,input().split())

This is a pattern in which the number of integers to be entered increases and becomes multiple. The A problem in AtCoder Beginner Contest 176 was this pattern. When entering multiple integers on one line, split () is built in so that they can be separated by spaces.

Enter an integer as a list

A = list(map(int,input().split()))

If the number to be entered is not fixed, the integer entered is stored in the list. The C problem in AtCoder Beginner Contest 176 was a combination of a single integer input and a list of integer inputs.

By learning these three input methods, you can avoid the standard input, which is the first stumbling block in competitive programming. Of course, there are many other input formats, but if you pursue them too much, your head will overheat. ** It is also important to declare proudly that you cannot remember. ** **

Summary / At the end

Avoid the first stumbling block "standard input" in competitive programming with the following three

#Enter one integer
a = int(input())
#Enter multiple integers
a,b,c = map(int,input().split())
#Enter an integer as a list
A = list(map(int,input().split()))

If you can solve problems A and B, you will be motivated to do competitive programming!

Recommended Posts

[For beginners of competitive pros] Three input methods to remember when starting competitive programming in Python
[For beginners] Summary of standard input in Python (with explanation)
Python3 standard input for competitive programming
Try to calculate RPN in Python (for beginners)
Introduction to Programming (Python) TA Tendency for beginners
Basic story of inheritance in Python (for beginners)
Data analysis in Python Summary of sources to look at first for beginners
Japanese translation of self-study "A Beginner's Guide to Getting User Input in Python"
[For beginners] How to use say command in python!
~ Tips for beginners to Python ③ ~
The minimum methods to remember when aggregating data in Pandas
Re: Competitive programming life starting from zero In order for beginners to get as high a performance as possible ~ ABC154 ~ 156 with impressions ~
Things to watch out for when using default arguments in Python
[For beginners] How to register a library created in Python in PyPI
Input / output method of values from standard input in competitive programming, etc.
Python techniques for those who want to get rid of beginners
Re: Competitive Programming Life Starting from Zero Chapter 1.2 "Python of Tears"
Run unittests in Python (for beginners)
Approach commentary for beginners to be in the top 1.5% (0.83732) of Kaggle Titanic_3
[Must read for beginners !?] Glossary of terms that stumbles when learning programming
Tips (input / output) that you should know when programming competitive programming with Python2
Procedure from AWS CDK (Python) development to AWS resource construction * For beginners of development
Approach commentary for beginners to be in the top 1.5% (0.83732) of Kaggle Titanic_1
Error due to UnicodeDecodeError when reading CSV file with Python [For beginners]
I refactored "I tried to make Othello AI when programming beginners studied python"
Introduction to Graph Database Neo4j in Python for Beginners (for Mac OS X)
Approach commentary for beginners to be in the top 1.5% (0.83732) of Kaggle Titanic_2
[Python] Minutes of study meeting for beginners (7/15)
"Python AI programming" starting from 0 for windows
Summary of various for statements in Python
Summary of built-in methods in Python list
[Competitive programming] [Python3] Required knowledge, for myself
Atcoder standard input set for beginners (python)
[python] What to do when an error occurs in send_keys of headless chrome
Things to keep in mind when using Python for those who use MATLAB
[For beginners] Unexpected behavior if "\" is included when setting the path in Python
Python script to get a list of input examples for the AtCoder contest
Memo # 4 for Python beginners to read "Detailed Python Grammar"
The fastest way for beginners to master Python
An introduction to object-oriented programming for beginners by beginners
Python for super beginners Python for super beginners # Easy to get angry
Summary of how to import files in Python 3
Memo # 3 for Python beginners to read "Detailed Python Grammar"
Summary of how to use MNIST in Python
Memo # 1 for Python beginners to read "Detailed Python Grammar"
Image processing? The story of starting Python for
Easy understanding of Python for & arrays (for super beginners)
Memo # 2 for Python beginners to read "Detailed Python Grammar"
Program to search all permutations (for competitive programming)
Prime factorization ver.2 of integers input in Python
List of Python code to move and remember
Memo # 7 for Python beginners to read "Detailed Python Grammar"
Error when trying to install psycopg2 in Python
Addition of fixed processing when starting python interpreter
Memo # 6 for Python beginners to read "Detailed Python Grammar"
How to make Python faster for beginners [numpy]
[For beginners] How to study programming Private memo
Memo # 5 for Python beginners to read "Detailed Python Grammar"
[Introduction for beginners] Working with MySQL in Python
[For beginners] Introduction to vectorization in machine learning
[Python] Building an environment for competitive programming with Atom (input () can be used!) [Mac]