This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#引数の受け取り | |
n,w = map(int,input().split()) | |
vw = [0]*n | |
#ビット全探索を行うために、ありうる組み合わせを全て作る | |
for i in range(0,n): | |
vw[i] = input().split() | |
p = [] | |
for i in range(2**n): | |
tmp = [0]*n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#引数の受け取り | |
n,w = map(int,input().split()) | |
vw = [0]*n | |
#ビット全探索を行うために、ありうる組み合わせを全て作る | |
for i in range(0,n): | |
vw[i] = input().split() | |
p = [] | |
for i in range(2**n): | |
tmp = [0]*n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Q15(s,a): | |
c = 0 | |
for i in range(0,len(s)): | |
if(s[i] == a): | |
c += 1 | |
return c | |
#文字列をリストとして考えて、1文字ずつfor文を使って先頭から探索していきます。 | |
#見つけたらカウンタとして用意しておいた変数cの値を1増やします。 | |
#別解として、s.count(a)とすれば1行で答えが出ます。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Q14(x1,y1,x2,y2): | |
a = (y2-y1)/(x2-x1) | |
b = y1-a*x1 | |
if(b>0): | |
s = ["y=",str(a),"x+",str(b)] | |
elif(b==0): | |
s = ["y=",str(a),"x"] | |
else: | |
s = ["y=",str(a),"x",str(b)] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Q13(n): | |
if(n == "test"): | |
return "Yes" | |
elif(n[-1] == "t"): | |
return "Good" | |
else: | |
return "No" | |
#条件判定の順番に気をつけて下さい。 | |
#testという文字列は末尾にtを含んでいるので、この条件を先に置くとtestに対して”Good”を出力してしまいます。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Q12(n): | |
s = list(n) | |
del s[5] | |
return ''.join(s) | |
#文字列はリストの要素のようにアクセスすることはできますが、削除は文字列のままでは出来ません。 | |
#考えられる方法としては、一度1文字ずつのリストに分解して、要素ごと消してjoinを使って再び文字列に戻して出力することで実装できます。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Q11(n): | |
return n[0:3] | |
#スライスを使えば簡単に実装できます。 | |
#Pythonの文字列操作でスライスは頻出です。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Q10(n): | |
for i in range(0,len(n)): | |
if(n[i] == "3"): | |
return i+1 | |
#色々やり方はあると思いますが、これが一番思いつきやすいと思います。 | |
#index関数を使ってもいいです。 | |
#配列の添字は0から始まっていることに注意して下さい。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Q8(n): | |
return int(1.12*n) | |
#税込価格は、税率がp、値段がnのとき、n(1+p)で表されます。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Q7(n): | |
if(n%2 != 0): | |
return "Yes" | |
else: | |
return "No" | |
#2で割り切れない数値は全て奇数です。 |
NewerOlder