LoginSignup
0
0

More than 3 years have passed since last update.

Python A問題対策(Atcorder)

Last updated at Posted at 2019-12-13

きっかけ

インターン先でPythonを用いた機械学習をする業務が増えたので、C++だけでなくAtcorderでPython3でも解けるように慣れていきたい!
ホントにPythonしらない(笑)

map関数、split関数


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

if a+b+c>=22:
    print("bust")
else:
    print("win")

#入力条件 3 4 7(空白を挟んで数値を代入している点に注目!)

map関数...複数値を入力するときに使われる!
split関数...何を基準に分けるか

文字列扱い

N=input() 
#int(input())と書かないことで、文字列(配列)となり、文字指定できる!
if N[0]==N[2]:
    print("Yes")
else:
    print("No")

and, orの使い方

A,B=map(int,input().split())

if((A+B)%3==0 or A%3==0 or B%3==0):
    print("Possible")
else:
    print("Impossible")

C++とPythonの対応...&& == and , || == or

改行の扱い方

N=int(input())
print(2*N)#改行している

改行したくない場合

N=int(input())
print(2*N,end="")#改行してない

型名取得

r,g,b=map(int,input().split())
ans=r*100+g*10+b
print(type(ans))

#出力結果
#>>> <class 'int'>

type関数を使えば一目瞭然!

まとめ

大体この4問を解いていれば、C++の経験があるとPythonでも全部解ける感じがする。次回はB問題から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