0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

標準入力・まとめ/python,ruby

Last updated at Posted at 2020-07-21

自分用メモとしてpaizaのスキルチェックやAtCoderなどでよく使いそうな標準入力をまとめました。

#基本
###文字

input.py
s = input()
input.rb
s = gets.chomp

###数値

python
n = int(input())
ruby
n = gets.chomp.to_i

#スペースで区切られてる場合
###スペースで区切られた値を個別の変数に数値として入力

input
1 2 3 
python
a,b,c = map(int,input().split())
#int カンマ input ドット split に注意
ruby
a,b,c = gets.chomp.split.map(&:to_i)

###スペースで区切られた値を個別の変数に文字として入力

input
red blue yellow 
python
a,b,c = input().split()
ruby
a,b,c = gets.chomp.split

###スペース区切りの値をリストに入力(文字・数値)

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]

#複数行
入力:n(行数)
   i1
   .
   .
   in

n行の値をリストに入力 [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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?