1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

今日はABSとやらに挑んでます。
めっちゃ簡単な問題から徐々にレベルアップしていくやつですね。
途中からしんどくなってくるやつ。

一番簡単なヤツ。というか、答え問題文の下に書いてあるし^^;;;

image.png

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

print(a+b+c,s)

2番目。今日覚えたif文短くするやつを使ってみる。

image.png

a,b=map(int,input().split())
print('Even') if a*b%2==0 else print('Odd')

3番目。いつも思う。「すぬけ君」ってどなた・・・。

image.png

この問題は文字列sの中に含まれる「1」の数を数えて出力しました。

s=input()
print(s.count('1'))

4番目。ぐぬぬ。難しくなってきた。

image.png

n=int(input())
a_lst=list(map(int,input().split()))    #入力をリストする

ck=0
ans=0

while ck==0:    #ckが0の間(偶数)はループさせる
    for a in a_lst: #リストの要素を順番にaに入れる
        if a%2!=0:  #aが偶数じゃなかったら
            ck=1    #ckを1(奇数)に変えて
            break   #forから抜ける
    if ck==0:   #ckが0(偶数)だったら
        a_lst=list(map(lambda x:x/2,a_lst)) #リストの要素を全部2で割る
        ans+=1  #操作をカウントアップ
print(ans)

5問目。小学生の問題か?と思ったら、苦戦した:dark_sunglasses:
全探索とか時間が・・・と思ったけど、他のいい答えが思い浮かばなかった。
所詮50^3なので時間はそれほどかからないのか。
そのあたりの感覚値がまだわからないんですよね。

image.png

a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0

# 全探索させる
for A in range(a+1):    #500円玉の数だけループ
    for B in range(b+1):    #100円玉の数だけループ
        for C in range(c+1):    #50円玉の数だけループ
            gokei=A*500+B*100+C*50  #合計額を計算
            if gokei==x:    #合計額がちょうどx円だったら
                ans+=1      #カウントアップ
print(ans) 

6問目。生意気にも自作関数などを作ってみた。
ちまちまfor文を書いていたのだけど、意味わからなくなってきたので、
各桁の総和を求めるところを切り取ったら、すんなりいった。
°˖☆◝(⁰▿⁰)◜☆˖°

image.png

#引数の各桁の総和を求める関数
def wa(suti):
    result=0
    for x in str(suti): #数値を文字列にして1桁ずつ取得
        result+=int(x)  #1桁ずつ足す
    return result       #足しあげたものを返す
    
n,a,b=map(int,input().split())
#整数1~nまでの間に各桁の総和がa以上b以下となる数値をリスト化
list=[i for i in range(1,n+1) if a<=wa(i)<=b]
#リストを全部足したものを出力
print(sum(list))

疲れたので、今日はここまで!( ´Д`)ノ~バイバイ

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?