0
0

More than 3 years have passed since last update.

【初心者が作る】競技プログラミングの備忘録

Last updated at Posted at 2020-12-06

この記事の目的

 競技プログラミングを始めてみました。軽く触って見た感じはすごく楽しいです。しかし、段々とストレスに感じることが出てきました。それは、一度調べたことを調べ直すことです。
 いちいち検索し直すのもめんどくさいので、リスト化してみようと思います。言語はPythonです
 ついでに、記事を発信する練習も兼ねています。

標準入力

1行内に書かれた一つの数字を取得する

return int(sys.stdin.readline().rstrip())

1行内に書かれ、空白で区切られた複数の数字を取得する(配列にする)

return list(map(int,sys.stdin.readline().rstrip().split()))

1行内に書かれた一つの文字列を取得する

return sys.stdin.readline().rstrip()

1行内に書かれ、空白で区切られた複数の文字列を取得する(配列にする)

return list(sys.stdin.readline().rstrip().split())

値の操作

数値を文字列に変換 文字列を数値に変換

str(数値) int(文字列)

値を1文字ずつ区切る(配列化)

list(値)

値を1文字ずつ区切って数値化)

list(map(int, list(str(数字))))

値の取得

配列の長さを取得

len(配列)

値の処理

割り算の答えを整数のみにする(pythonは割り算するとfloat型になる)

a // b

繰り返し処理

回数指定の繰り返し
for i in range(回数):
配列のループ処理(index無し)
list1 = ['item1', 'item2', 'item3']
for item in list1:
    print(item)
配列のループ処理(index有り)
list1 = ['item1', 'item2', 'item3']
for index, item in enumerate(list1):
    print("インデックス:" + str(index) + ", 値:" + item)

参照

Python配列のループ処理

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