Puisque je suis un débutant en programmation, j'étudierai à la sélection des débutants d'AtCoder. Le langage utilisé est le python.
Ma réponse
ans1.py
a = int(input())
b,c = map(int,input().split())
s = input()
 
print(a+b+c,s)
Ma réponse
ans2.py
a,b = map(int, input().split())
 
if (a*b) % 2 == 0:
    print("Even")
else:
    print("Odd")
print(a+b+c,s)
Ma réponse
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)
Cette méthode n'est pas courante. .. Plus tard, j'ai découvert l.count ('1').
Ma réponse
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)
Ma réponse
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)
Recherche complète? je me demande si
Ma réponse
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())
Le nom de la variable est trop texto. ..
Ma réponse
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())
Enregistré par tri.
Ma réponse
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)
Je ne pense pas que ce soit intelligent.
Ma réponse ① (mauvaise réponse)
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)
En fonction du code de test, divers résultats tels qu'une réponse correcte, une réponse incorrecte et un temps de dépassement ont été obtenus.
Ma réponse ② (mauvaise réponse)
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)
Introduction d'une variable d'indicateur au lieu de exit () pour sortir de la boucle. Encore une fois, le code de test a donné divers résultats tels qu'une réponse correcte, une réponse incorrecte et un temps de dépassement. Je ne sais pas ce qui ne va pas, alors aidez-moi s'il vous plaît! (→ Résolu. Vous n'avez pas besoin du troisième pour !!)
Ma réponse ③ (bonne réponse)
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)
Ma réponse
ans9.py
S = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if (len(S) == 0):
    print('YES')
else:
    print('NO')
C'est un remplacement de chaîne replace ().
Recommended Posts