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?

PaizaとかAtcoderで必要な入力の処理

Posted at

目的

自分のプログラミング学習のためにPaizaのスキルチェックとかAt coderちょこちょこやってるけど,あまりに期間が空いて毎回入力の処理どうするんだっけ…?ってなるので確認用の生地を作成

入力の受け取り方

input関数の利用

まず,標準入力を受け取るにはinput関数を使わないといけない.
変数= input()とすれば,基本的にstrで標準入力の中身を受け取る

標準入力の受け取り方
x = input()

atcodedrやPaizaでは標準入力はいろんなパターンで渡される
そのため,いろいろなinput関数の使い方がわかっていた方がよい

1行に1つの入力を取得

x = input()

1行に複数の入力を取得

input: 1 10 11

s = input().split()
print(s)
# 出力 ['1', '10', '11']
# spliitに値を渡せばそれに応じて標準入力の区切りに応じた対応ができる

# 整数として処理したい場合は…
s = list(map(int, input().split()))
# 出力 [1, 10, 11]

複数行に複数の入力を取得

input:
1
10
11

s = [input() for i in range(3)]
print(s)
# 出力 ['1', '10', '11']
# 整数として処理したい場合は…
s = [int(input()) for i in range(3)]
print(s)
# 出力[1, 10, 11]

入力回数が最初に与えられるパターン

input:
N
1
11
111
...
N
N = int(input()) #1行目のNを取得する
s = [input() for i in range(N)] #複数行の数値の入力を取得
print(s) #出力:[1, 10, 11, ... ,N]
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?