Standard input / summary / python, ruby

As a memo for myself, I have summarized the standard input that is likely to be used frequently in paiza's skill check and AtCoder.

Basic

letter

input.py


s = input()

input.rb


s = gets.chomp

Numerical value

python


n = int(input())

ruby


n = gets.chomp.to_i

Separate with a space

Enter space-separated values as numbers in individual variables

input


1 2 3 

python


a,b,c = map(int,input().split())
#Note the int comma input dot split

ruby


a,b,c = gets.chomp.split.map(&:to_i)

Enter space-separated values as characters in individual variables

input


red blue yellow 

python


a,b,c = input().split()

ruby


a,b,c = gets.chomp.split

Enter space-separated values in the list (characters / numbers)

input


spring summer autumn winter
101 102 103 104

python


x = input().split()
y = list( map(int,input().split()) )

ruby


x = gets.chomp.split
y = gets.chomp.split.map(&:to_i)

output


#x
["spring","summer","autumn","winter"]
#y
[101,102,103,104]

Multiple lines

Input: n (number of lines)    i1    .    .    in

Enter n rows of values in the list [i1, i2, i3, ....., in]

python


n = int(input())
I = [ input() for i in range(n) ]

ruby


n = gets.chomp.to_i
array = []
n.times do
 i = gets.chomp
 array.push(i)
end

Recommended Posts

Standard input / summary / python, ruby
[Python] Standard input
Standard input summary
[Python] About standard input
Standard input / output summary
[Python3] Standard input [Cheat sheet]
Receiving standard input tips @ python
Python Summary
Python summary
Matrix representation with Python standard input
[For beginners] Summary of standard input in Python (with explanation)
Python Paiza-Various skill checks and standard input
Python tutorial summary
Python3 standard input I tried to summarize
Python standard input summary that can be used in competition pro
python related summary
Atcoder standard input set for beginners (python)
[Python] Add comments to standard input files
Python basics summary
Correspondence summary of array operation of ruby and python
Python vs Ruby "Deep Learning from scratch" Summary
Python: Use zipfile to unzip from standard input
Summary about Python scraping
Key input in Python
Python Django tutorial summary
Ruby, Python and map
Summary about Python3 + OpenCV3
Python function argument summary
python input and output
Python and Ruby split
Python audio input / output
Python directory operation summary
Python AI framework summary
Python iteration related summary
Memorize Python commentary 4 --Input
Summary of Python arguments
Key input in Python
Have python parse the json entered from the standard input
[Python] Change standard input from keyboard to text file
Which is better, python standard input receiving input () or sys.stdin?
Cisco Memorandum _ Python config input
Python3 programming functions personal summary
Summary of python file operations
Summary of Python3 list operations
Python on Ruby and angry Ruby on Python
Python 3.4 or later standard pip
Java VS PHP VS Python VS Ruby
What's new in Python 3.10 (Summary)
Write standard input in code
Standard input with time limit
Python standard unittest usage notes
Part 1 of receiving standard input
Python and ruby slice memo
Python Input Note in AtCoder
Python class member scope summary
Python web programming article summary
Zundokokiyoshi with python / ruby / Lua
About Perl, Python, PHP, Ruby
Transposed matrix in Python standard
Summary of Hash (Dictionary) operation support for Ruby and Python
Ruby and Python syntax ~ branch ~