AtCoder Beginners Selection memorandum

Since I am a beginner in programming, I will study at Beginners Selection of AtCoder. The language used is python.

スクリーンショット 2020-02-19 14.35.08.png My answer

ans1.py


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

スクリーンショット 2020-02-19 14.37.54.png 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)

スクリーンショット 2020-02-19 14.38.51.png 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').

スクリーンショット 2020-02-19 14.41.25.png 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)

スクリーンショット 2020-02-19 14.44.12.png 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

スクリーンショット 2020-02-19 14.46.27.png 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. ..

スクリーンショット 2020-02-19 14.49.28.png 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.

スクリーンショット 2020-02-19 15.09.19.png 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.

スクリーンショット 2020-02-20 15.32.47.png 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)

スクリーンショット 2020-02-21 13.05.57.png 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

AtCoder Beginners Selection memorandum
AtCoder Beginners Selection Experience (2nd time)
Answer to AtCoder Beginners Selection by Python3
AtCoder Beginner Contest 167 Memorandum
[Answer example (python3)] ABS (AtCoder Beginners Selection) of atcoder
About python beginner's memorandum function
Linux command memorandum [for beginners]
AtCoder Beginners Contest Past Question Challenge 6
AtCoder Beginners Contest Past Question Challenge 4
AtCoder Beginners Contest Past Question Challenge 9
AtCoder Beginners Contest Past Question Challenge 7
AtCoder Beginners Contest Past Question Challenge 10
# 2 Python beginners challenge AtCoder! ABC085C --Otoshidama
AtCoder Beginners Contest Past Question Challenge 5
Memorandum of beginners Python "isdigit" movement
Memorandum of python beginners About inclusion notation
Atcoder standard input set for beginners (python)