[PYTHON] The story of participating in AtCoder

I participated in AtCoder for the first time

While writing articles on Qiita and researching various things about work I learned that "competitive programming" is popular. Since articles on Twitter etc. are flowing to TL, create an account with interest. After a lot of research, it seems that the contest will be held on Friday nights and holiday nights. It seems that he will participate there and solve the problem.

I was busy during the New Year holidays, and I was only able to create an account, so I was finally able to participate in the contest. I participated for the first time AtCoder Beginner Contest 151. Recently, I often play with kintone, so I thought I'd try it with js. It doesn't seem to be recommended, so I participated in Python, which I studied a little a few months ago.

It ’s the first time, so what ’s wrong?

Waiting in front of the PC while pounding, start at the right time. A countdown is displayed at the bottom right of the screen. There were 6 questions from A to F, and the points were different for each question (A is 100 points and increases by 100 points).

The problems are lined up in a row, and I'm not sure, but I chose A's problem because A is for beginners. I wrote about the execution time limit, but ignore it for the time being ...

Solved problem ABC 151 A-Next Alphabet

** [Problem sentence] ** Given a lowercase $ C $ that is not $ z $. Output the next character of $ C $ in alphabetical order. ** [Constraints] ** $ C $ is a lowercase letter other than $ z $ ** [Input] ** Input is given from standard input in the following format. C ** [Output] ** Output the next character of $ C $ in alphabetical order. ** [Input example] ** a ** [Output example] ** b

Try to participate

・ First of all, I get stuck in the word standard input. ・ Knowledge of Python is missing. ・ It was difficult to shift from JavaScript to the idea of arrays in Python.

Although I solved it for the time being, it became a crappy code, so I will post it as a commandment. I wonder if I should have checked the libraries and methods.

alpha.py


a = input()
alpha = ["a", "b", "c", "d", "e", "f", "g",
        "h", "i", "j", "k", "l", "m", "n",
        "o", "p", "q", "r", "s", "t", "u",
        "v", "w", "x", "y", "z"]

for i in range(len(alpha)):
    alphabet = alpha[i]
    if a == alphabet:
        s = i + 1
        alphabet = alpha[s]
        print(alphabet)
        break

This code took 17ms while the execution time limit was written as 2sec. Completely out. I thought this was addictive the moment I finished.

At the end

AtCoder also publishes past questions, so when you have time such as holidays I will practice writing. First of all, I felt that it was important to participate in some kind of contest every week and get used to it. Next time, I'll write the code so that I can solve it while paying attention to the execution time!

Recommended Posts

The story of participating in AtCoder
The story of the "hole" in the file
The story of an error in PyOCR
The story of sys.path.append ()
The story of finding the optimal n in N fist
The story of reading HSPICE data in Python
The story of viewing media files in Django
The story of building Zabbix 4.4
[Apache] The story of prefork
The story of building the fastest Linux environment in the world
The story of FileNotFound in Python open () mode ='w'
The story of Python and the story of NaN
The meaning of ".object" in Django
The story of remounting the application server
The story of writing a program
The story of downgrading the version of tensorflow in the demo of Mask R-CNN.
Wrap (part of) the AtCoder Library in Cython for use in Python
The story of outputting the planetarium master in pdf format with Pycairo
The story of trying to reconnect the client
[Understanding in 3 minutes] The beginning of Linux
Check the behavior of destructor in Python
The story of verifying the open data of COVID-19
The story of adding MeCab to ubuntu 16.04
The story of making Python an exe
Implement part of the process in C ++
The story of making an immutable mold
The result of installing python in Anaconda
Let's claim the possibility of pyenv-virtualenv in 2021
The story of manipulating python global variables
The basics of running NoxPlayer in Python
The story of trying deep3d and losing
The story of deciphering Keras' LSTM model.predict
In search of the fastest FizzBuzz in Python
The story of blackjack A processing (python)
The story of pep8 changing to pycodestyle
The story of a Parking Sensor in 10 minutes with GrovePi + Starter Kit
Output the number of CPU cores in Python
The meaning of {version-number} in the mysql rpm package
The story of low learning costs for Python
[Python] Sort the list of pathlib.Path in natural sort
Change the font size of the legend in df.plot
Get the caller of a function in Python
Match the distribution of each group in Python
View the result of geometry processing in Python
The story of making the Mel Icon Generator version2
Make a copy of the list in Python
Find the number of days in a month
Read the output of subprocess.Popen in real time
Find the divisor of the value entered in python
Image processing? The story of starting Python for
The story of making a lie news generator
The story of misreading the swap line of the top command
Fix the argument of the function used in map
Find the solution of the nth-order equation in python
[Note] About the role of underscore "_" in Python
Put the second axis in 2dhistgram of matplotlib
About the behavior of Model.get_or_create () of peewee in Python
Solving the equation of motion in Python (odeint)
Visualized the usage status of the sink in the company
Output in the form of a python array
The story of trying Sourcetrail × macOS × VS Code