LoginSignup
0
0

More than 3 years have passed since last update.

HackerRnakメモ

Posted at

HackerRnakメモ

個人メモです

基本使用言語

python3

raw_input()
キーボード入力(python2)
python3の場合はinput()

n = input()
n = int(input())

.strip()
空白文字(スペース、タブ、改行)の削除

input().strip()

sprit()
指定した文字で区切り配列にする。
()内に指定がない場合は、スペースやTABで区切る

input().split()

STDIN
キーボード入力された値
標準入力

・difference
差分
difference of the two numbers (first - second).

・puroduct
掛け算
product of the two numbers.

a//b
割り算。商を整数で返す
小数点以下は切り捨て

for文
for 変数 in シーケンス

n = int(raw_input())

for i in range(n):
   print(i*i)

range(n)
i<n
i=0から
nは含まない。

range(3) = [0,1,2]

・Leap Day
うるう年
We add a Leap Day on February 29.

・intercalary day
差し込まれた日
The leap day is an extra, or intercalary day.

・evenly divided by ~
~で割り切れる
The year can be evenly divided by 4, is a leap year.

if文
if, elif, elseの後に「:」必須。

sum(配列)
合計値を算出

list = range(5)
print(sum(list)) 

str()
文字列に変換

n = int(input())

a=""
for i in range(n):
   a =a+str(i+1)
print(a)

#出力
a=12345~

・arithmetic operations
算術演算子。 +-*%のこと

・runner-up
準優勝
you are required to find the runner-up score.

(lambda 変数:処理)(引数)
ラムダ関数
1行で関数を作れる(def相当)
(lambda 変数:処理)(引数)
 └ 引数を処理に代入する
 └ 引数は複数可。順位処理内の変数に入る。

print((lambda a,b,c:a*100+b*10+c*1)(1,2,3))

#出力
123

map(関数, 配列)
map関数
配列の要素一つ一つに関数を実行する。
出力はmapオブジェクト
→ list(map())でlistオブジェクトに変換

・map関数を使って配列を整数に変換する
map = (int, 配列)

arr = map(int, input().split())

x**y
べき乗。xのy乗

10*0 = 0
10
*3 = 1000

set()
配列から重複する値を削除
set型

arr=[2,3,6,6]
print(set(arr))

{2,3,6}

sorted()
配列を昇順に並べる

n番目に大きい値を抜き出す
sorted()[-n]

#2番目に大きい値を抜き出す
arr=[2,3,6,6,5]

sorted(set(arr))[-2]

#出力
5

・order their names alphabetically
アルファベット順に並べる
order their names alphabetically and print each one on a new line.

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