Qiita Teams that are logged in
You are not logged in to any team

Community
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What is going on with this article?
@miyapirau

# AtCoder Beginners Selection 備忘録

More than 1 year has passed since last update.

プログラミング初心者なので、AtCoderのBeginners Selectionで勉強します。

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

print(a+b+c,s)
``````

ans2.py
``````a,b = map(int, input().split())

if (a*b) % 2 == 0:
print("Even")
else:
print("Odd")
print(a+b+c,s)
``````

ans3.py
``````a = input()
l = [int(x) for x in list(str(a))]

sum = int(l[0])+int(l[1])+int(l[2])
print(sum)
``````

このやり方は一般的ではないですね。。後に、l.count('1')というものを知りました。

ans4.py
``````import numpy as np

N = input()
l = list(map(int, input().split()))
array = np.array(l)

i = 0

while sum(array % 2) == 0:
array = array/2
i = i++

print(i)
``````

ans5.py
``````A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0

for a in range(A+1):
for b in range(B+1):
for c in range(C+1):
if X == 500*a + 100*b + 50*c:
count = count + 1

print(count)
``````

ans6.py
``````import numpy as np

N,A,B = map(int,input().split())
count = 0
l2 = []

for i in range(1,N+1):
l = np.array([int(x) for x in list(str(i))])
if A <= np.sum(l) & np.sum(l) <= B:
l2.append(i)

l3 = np.array(l2)
print(l3.sum())
``````

ans6.py
``````import numpy as np

N = int(input())
a = np.array(list(map(int,input().split())))

sort = np.sort(a)[::-1]

alice = sort[::2]
Bob = sort[1::2]

print(alice.sum() - Bob.sum())
``````

sortに救われています。

ans7.py
``````import numpy as np

N = int(input())
l = []
count = 1

for i in range(N):
l.append(int(input()))

array = np.sort(np.array(l))

for i in range(len(array)-1):
if array[i] != array[i+1]:
count = count + 1

print(count)
``````

なんかスマートじゃない気もする。

ans8_1.py
``````import sys

N,Y = map(int,input().split())

for i1 in range(N+1):
for i2 in range(N+1-i1):
for i3 in range(N+1-i1-i2):
if 10000*i1 + 5000*i2 + 1000*i3 == Y:
print(i1,i2,i3)
sys.exit()
print(-1,-1,-1)
``````

テストコードによって正解、不正解、実行時間超過という様々な結果が得られた。

ans8_2.py
``````N,Y = map(int,input().split())
flag = False

for i1 in range(N+1):
for i2 in range(N+1-i1):
for i3 in range(N+1-i1-i2):
if 10000*i1 + 5000*i2 + 1000*i3 == Y:
print(i1,i2,i3)
flag = True
break
if flag:
break
if flag:
break

if flag-1:
print(-1,-1,-1)
``````

ループを抜けるために、exit()ではなく、flag変数を導入した。これもテストコードによって正解、不正解、実行時間超過という様々な結果が得られた。何が不正解なのかわからないのでだれか助けてほしい！（→解決した。三つ目のforは要らないね!!)

ans8_3.py
``````N,Y = map(int, input().split())
for i1 in range(N+1):
for i2 in range(N+1-a):
i3 = N-i1-i2
if 10000*i1 + 5000*i2 + 1000*i3 == Y:
print(i1,i2,i3)
exit()
print(-1,-1,-1)
``````

ans9.py
``````S = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if (len(S) == 0):
print('YES')
else:
print('NO')
``````

2
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away