[PYTHON] Easy way to enter and execute AtCoder test cases in Jupyter Notebook

Introduction

Do you guys do Atcoder? ?? I also look interesting! I thought that I started with Python. However, when it comes to writing code in a contest

The code test on the contest site is troublesome to move pages ... PyCharm is a little heavy to say ...

I felt like I couldn't find the right coding environment. .. And after trying various things, Jupyter Notebook seems to be just right! I've realized that, so I'd like to share it!

Introducing immediately

First of all, Jupyter Notebook is good! Perfect! If so, this article should end here

There is only one thing that is not very suitable for AtCoder.

That is, "there is no way to enter test cases well"! I want to receive input with input (), but I can't receive it because it is not prepared. ..

Therefore! Introducing "Easy way to receive AtCoder test cases in Jupyter Notebook".

Now open your notebook. Paste the code below into the first cell.

from ipywidgets import Textarea

def get_input(change):
    global Input
    Input = change["new"]

textarea = Textarea()
textarea.observe(get_input, names='value')
display(textarea)

And execute the cell ... Then a text area will appear! セル1.JPG You can enter multiple lines in this text area, and you can paste the test case as it is!

continue, Create a cell below and paste the code below.

IN = iter(Input.split('\n')).__next__
def input():
    return IN()

That's all for preparation! セル2.JPG

Try using

Try it in "A-Welcome to At Coder" of Atcoder's resident contest "practice".

Problem statement

Takahashi wants to process the data. Given the integers a, b, c and the string s. Display the calculation result of a + b + c and the character string s side by side.

input

The input is given in the following format.

a
b c
s

output

Output a + b + c and s on one line separated by spaces.


Input example 1

1
2 3
test

Output example 1

6 test

By the way, it is a type that has multiple lines of input. Let's paste the input example into the text area prepared earlier! 実践1.JPG It has been cut off, but it has been pasted.

Then code. Write the code in the second cell. 実践2.JPG When I ran it ... it worked! It gets line by line from the text area with input ().

All you have to do is submit the code and you'll be happy to finish! Let's pray for AC (be careful not to accidentally include the preparation code) 提出.JPG

in conclusion

How was that? ??

You can try various inputs quickly with a little preparation, so I think it will be quite comfortable! If you are worried that you haven't found a coding environment that suits you yet, please try it ~

See you soon

Recommended Posts

Easy way to enter and execute AtCoder test cases in Jupyter Notebook
How to execute commands in jupyter notebook
Easy to use Jupyter notebook (Python3.5)
A simple way to launch Jupyter Notebook / Lab and set a password
Easy way to use Wikipedia in Python
Get, test, and submit test cases on the command line in the AtCoder contest
A memorandum of how to execute the! Sudo magic command in Jupyter Notebook
Build a PYNQ environment on Ultra96 V2 and log in to Jupyter Notebook
[Small story] Easy way to convert Jupyter to PDF
Use ipywidgets in jupyter notebook to interactively manipulate parameters and also try image processing
[Mac] A super-easy way to execute system commands in Python and output the results
It is easy to execute SQL with Python and output the result in Excel
An easy way to create an import module with jupyter
Automatically save .py and .html files in Jupyter notebook.
An easy way to view the time taken in Python and a smarter way to improve it
How to import NoteBook as a module in Jupyter (IPython)
How to use pyenv and pyenv-virtualenv in your own way
Tips for coding short and easy to read in Python
A standard way to develop and distribute packages in Python
The usual way to add a Kernel with Jupyter Notebook
Unable to display tensorboard in jupyter notebook on docker (solved)
How to import NoteBook as a module in Jupyter (IPython)
A very convenient way to give a presentation on Jupyter Notebook
How to execute external shell scripts and commands in python
PyArmor ~ Easy way to encrypt and deliver python source code ~
How to log in to AtCoder with Python and submit automatically
Introduced Jupyter Notebook to CentOS 7
Display HTML in Jupyter notebook
Multiprocessing error in Jupyter Notebook
Easy way to rename files
How to use Jupyter Notebook
An easy way to hit the Amazon Product API in Python
How to resolve ModuleNotFoundError: No module named XXX in Jupyter Notebook
Regular expressions that are easy and solid to learn in Python
An easy way to re-execute a previously executed command in ipython
Use Jupyter Notebook as a unit test and manual creation tool
Install Anaconda on Mac and upload Jupyter (IPython) notebook to Anaconda Cloud
How to display bytes in the same way in Java and Python