Since I am a beginner in programming, I will study at Beginners Selection of AtCoder. The language used is python.
My answer
ans1.py
a = int(input())
b,c = map(int,input().split())
s = input()
print(a+b+c,s)
My answer
ans2.py
a,b = map(int, input().split())
if (a*b) % 2 == 0:
print("Even")
else:
print("Odd")
print(a+b+c,s)
My answer
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)
This method is not common. .. Later, I found out about l.count ('1').
My answer
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)
My answer
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)
Full search? I wonder if
My answer
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())
The variable name is too texto. ..
My answer
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())
It is saved by sort.
My answer
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)
I don't think it's smart.
My answer ① (wrong answer)
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)
Depending on the test code, various results such as correct answer, incorrect answer, and overrun time were obtained.
My answer ② (wrong answer)
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)
Introduced a flag variable instead of exit () to get out of the loop. Again, the test code gave various results such as correct answer, incorrect answer, and overrun time. I don't know what's wrong, so please help me! (→ Solved. You don't need the third for !!)
My answer ③ (correct answer)
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)
My answer
ans9.py
S = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if (len(S) == 0):
print('YES')
else:
print('NO')
It's a string replacement replace ().
Recommended Posts