LoginSignup
9
12

More than 3 years have passed since last update.

コーディングテスト受けたくない

Last updated at Posted at 2019-12-11

コーディングテスト受けたくない

コーディングテスト受けるので、メモしておく。
メモしていくので更新します。
テキトーなので勘弁してください

2019/12/15
取り敢えず、普段使っているpythonでやります。
競プロだったら、C++に移行した方がいい?

2019/12/16
AtCoderの過去問を解きたい
取り敢えず、githubのリポジトリ作った。
βshortのリポジトリ

競プロ関係?

paiza
AOJ
AtCoder

問題

  1. AtCoder Beginners Selection
  2. AtCoderの問題

参考&リンク

  1. AtCoder に登録したら次にやること ~ これだけ解けば十分闘える!過去問精選 10 問 ~
  2. Pythonで使う競技プログラミング用チートシート
  3. https://1kohei1.com/leetcode/
  4. https://www.madopro.net/entry/2016/09/05/135126
  5. https://www.freecodecamp.org/news/coding-interviews-for-dummies-5e048933b82b/
  6. https://qiita.com/yohachi/items/e4bef4035da135a4808d
  7. https://app.codility.com/programmers/lessons/1-iterations/
  8. AtCoder に登録したら解くべき精選過去問 10 問を別解で解いてみた

Pythonのメモ

文法的なこと、numpy関係のメモです。

入力関係

参考:https://qiita.com/fmhr/items/77fc453e2fb1bc02e392

複数の数値を指定の変数に

a, b, c, d = map(int, input().split())

複数の数値をリストに

#入力 1 3 4 5
a = [int(i) for i in input().split()] 
#a=[1 3 4 5]

複数の文字列をリストに

a = [i for i in input().split()] 

出力関係

ゼロ埋め出力

複数の場合インデックスで指定
2桁の10進の場合

#{インデックス番号:書式指定}.format()
print("{0:02d}".format(1))
#01

改行なし

print("文字など", end='')

小数点

#切り上げ
math.ceil()
#切り捨て
math.floor()
#四捨五入
round()

n進数

2進数:bin()
8進数:oct()
16進数 : hex()

一致

全一致 'abc' == 'abcd' はFalse
否定は !=

部分一致 'abc' in 'abcd' はTrue
否定は、not in

文字列

文字列sに'a'が何個あるか

s.count('a')
s.replace("置換前", "置換後")

指定したインデックスの文字を置換(代入)したい

#文字列=>list
s = list("文字列")
s[2] = "式"
s = "".join(s) 

list

https://docs.python.org/ja/3/tutorial/datastructures.html
各要素の個数(要素ごとの出現回数)をカウントするには、count()メソッドを使う。

a.append("格納したい値")
a.remove("削除したい値")
a.pop()

リスト内包表記

[i for i in range(10)]
#昇順
a.sort()
#降順
a.sort(reverse=True)
sum(a)

mapは、pandasでいうapply関数

map(func, list)

set

a.add()
a.delete()

dict

numpy

np.zeros('shape')
np.ones('shape')
np.full('shape', 'value')

条件を満たす配列の要素数

np.count_nonzero(a < 4)

配列の最大値のインデックス

#https://qiita.com/shippokun/items/01c85e36b8de7afd01a6

maxValue = np.max(a)
maxIndex = []
for i in range(len(a)):
    if maxVaule == a[i]:
        maxIndex.append(i)
print(maxIndex)    # [1, 4]

numpy配列の各要素に対しての条件分岐

np.where(条件, True, False))
9
12
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
9
12