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.
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, 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 ...
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. ** **
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.
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.
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. ** **
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