Hello. It's chewy and chewy. We will solve the introduction to AOJ's algorithms and data structures. It's easy to keep a record of what you've learned.
It's been less than half a year since I started programming myself AtCoder is green, so I'm not a strong man. Let's work hard together.
Ah, let's go
This time is PART1: Introduction. I want to do my best and do it to the end.
ALDS1_1_A: Insertion sort ALDS1_1_B: Greatest common divisor ALDS1_1_C: Prime number ALDS1_1_D: Maximum profit
Insertion sort
n = int(input())
A = list(map(int,input().split()))
print(*A)
for i in range(1,n):
v = A[i]
j = i-1
while j >= 0 and A[j]>v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
print(*A)
The greatest common divisor is calculated by Euclid's mutual aid method.
def gcd(a,b):
while b:
a, b = b, a%b
return a
x,y = map(int,input().split())
print(gcd(x,y))
It is O (n ** 0.5) to judge whether it is a prime number
n = int(input())
input_list = []
for _ in range(n):
a = int(input())
input_list.append(a)
def prime(n):
if n==1:
return False
else:
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
else:
return True
ans = 0
for i in input_list:
if prime(i):
ans += 1
print(ans)
Stock Forecast No Absolute
n = int(input())
a = []
for _ in range(n):
b = int(input())
a.append(b)
minv = a[0]
maxv = -10**18
for i in range(1,n):
b = a[i]
maxv = max(maxv,b-minv)
minv = min(minv,b)
print(maxv)
If you have a wrong answer, please contact Goto
p.s.p I've never received a Qitta like guy We are looking forward to the first memorable relatives.
Recommended Posts