[PYTHON] I tried competitive programming

I'm studying because I want to be an engineer, but I can't find a job easily. (I know the portfolio is bad)

So I'm playing with python to kill time (use that time to repair the portfolio!)

I've been trying to solve each question from Paiza's D rank since about 3 days ago.

__pleasant! !! !! __

I've been studying the basics, but almost no output has come

I think it's a good place for output for me.

However, I can do competitive programming = I don't think I can work as an engineer, so be careful?

e? Isn't Paiza competitive programming?

Real competitive programming because the question format is similar! So

I knew competitive programming when I was solving Paiza's problem and looking up the syntax.

I will try AtCoder after playing with Paiza that can be done with one screen (It's not a hassle to prepare tools)

From here on, the problems and syntax that I experienced

First from the rudimentary FizzBuzz problem When outputting numbers from 1 to 100, Outputs'Fizz' when it is a multiple of 3,'Buzz' when it is a multiple of 5, and'FizzBuzz' when it is a multiple of 3 and 5. Problem

I think many people who are learning programming have done it First from the general writing style

.py


for i in range(1, 101):
  if i % 3 == 0 and i % 5 == 0:
    print('FizzBuzz')
  elif i % 3 == 0:
    print('Fizz')
  elif i % 5 == 0:
    print('Buzz')
  else:
    print(i)

The heart of this problem is first whether the decision is a multiple of 3 and 5. (Please check each one for detailed explanation) To put it simply, "too much divided by 15 is 0" ⊃ "too much divided by 3 (5) is 0" The order of judgment of the remaining multiples of 3 and 5 does not matter, so it is correct to write from either side.

Competitive programming is about writing this more concisely. I was impressed when I first called

.py


for i in range(1, 101):
  print('Fizz' * (i % 3 == 0) + 'Buzz' * (i % 5 == 0) or i)

How can I write in 2 lines It can be written in just one line, so it can still be improved, but if you draw it so beautifully, it will be impressive enough.

First When two input values ​​M and N (separated by half-width spaces) are given, Outputs'YES'when the evenness of M and N match, and'NO' when not.

If you write it normally, it will be long, so I will omit it This is what I wrote


n, m = map(int, input().split())
print('NO' * (n % 2 == m % 2) or 'YES')

If there are 100 coders, there are 100 ways to write, so for reference only

I tried to introduce some of them, but when I looked back, I didn't write anything amazing, but it was written down, so I will omit it.

That's all for the fun of competition professionals

P.S. C ++ seems to be the fastest in the competition pro, so I started to touch C ++ (Job hunting)

Recommended Posts

I tried competitive programming
I tried shell programming
I tried scraping
I tried PyQ
I tried AutoKeras
I tried papermill
I tried django-slack
I tried Django
I tried spleeter
I tried cgo
I tried using parameterized
I tried using argparse
I tried using mimesis
I made a competitive programming glossary with Python
I tried using anytree
I tried running pymc
I tried ARP spoofing
I tried using aiomysql
I tried using Summpy
I tried Python> autopep8
Competitive programming diary python 20201213
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried python programming for the first time.
I tried using ESPCN
I tried PyCaret2.0 (pycaret-nightly)
I tried using openpyxl
I tried deep learning
I tried AWS CDK!
Competitive programming diary python 20201220
I tried using Ipython
I tried to debug.
Competitive programming with python
I tried using Pythonect, a dataflow programming language.
I tried using PyCaret
I tried using cron
I tried Kivy's mapview
I tried using ngrok
I tried using face_recognition
I tried to paste
I tried using Jupyter
I tried using PyCaret
I tried moving EfficientDet
I tried using Heapq
I tried using doctest
I tried Python> decorator
I tried running TensorFlow
I tried Auto Gluon
I tried using folium
I tried using jinja2
Competitive programming diary python
I tried AWS Iot
I tried Bayesian optimization!
I tried using the functional programming library toolz
I tried using folium
I tried using time-window
I participated in competitive programming in a week after I started programming
I tried increasing or decreasing the number by programming