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.
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 ...
** [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
・ 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.
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