CAU12.
Kiểm tra CSC
with open("[Link]","r") as fin:
data=[Link]()
l=int(data[0])
s=list(map(int,data[1].split()))
d=s[2]-s[1]
for i in range(1,l-1):
if s[i+1]-s[i]!=d:
result="FALSE"
else:
result="TRUE"
with open("[Link]","w") as fout:
[Link](result)
CAU2. Tìm max, chỉ số phần tử đầu tiên max
with open("[Link]", "r") as f:
n = int([Link]().strip())
a = list(map(int, [Link]().strip().split()))
max_value = max(a)
first_max_index = [Link](max_value)
with open("[Link]", "w") as f:
[Link](f"{max_value}\n")
[Link](f"{first_max_index + 1}\n")
CAU3. Tìm max, chỉ số tất cả phần tử max
with open("[Link]", "r") as f:
data = [Link]()
klinh = list(map(int, data[0].split()))
gtln = max(klinh)
chiso = [hello + 1 for hello, num in enumerate(klinh) if num == gtln]
with open("[Link]", "w") as f:
[Link](str(gtln) + "\n")
[Link](" ".join(map(str, chiso)))
CAU15. Số phần tử vị trí lẻ, giá trị lẻ
with open ("[Link]","r") as f:
data=[Link]()
N=list(map(int,data[1].split()))
dem=0
for i in range(len(N)):
if i%2==0 and N[i]%2==1:
dem+=1
with open("[Link]", "w") as f:
[Link](str(dem))
CAU17. Sắp xếp 2 dãy tăng dần
with open("[Link]", "r") as f:
data=[Link]()
a=list(map(int,data[0].split()))
b=list(map(int,data[1].split()))
c=a+b
a1=list(sorted(a))
a2=' '.join(str(x) for x in a1)
b1=list(sorted(b))
b2=' '.join(str(y) for y in b1)
c1=list(sorted(c))
c2=' '.join(str(z) for z in c1)
S=a2+"\n"+b2+"\n"+c2
with open("[Link]", "w") as f:
[Link](str(S))
024HH. Số bằng tổng ước không kể nó
with open("[Link]","r")as fin:
data=[Link]()
N=int(data[0])
a=0
for i in range(2,N+1):
u=[b for b in range(1,i)if i%b==0]
hh=sum(u)==i
if hh:
a+=1
with open("[Link]","w")as fout:
[Link](str(a))
015TD. Tổng và TB phần tử
with open("[Link]", "r") as f:
data=[Link]()
n=list(map(int,data[0].split()))
s=0
for x in range(len(n)):
N=int(n[x])
s=s+N
tb=s/len(n)
with open("[Link]", "w") as f:
[Link](str(s)+" "+format(tb,".3f"))
015TD02. Số phần tử lớn hơn TB các phần tử chẵn
with open("[Link]", "r") as f:
data=[Link]()
N=list(map(int,data[0].split()))
ssh=0
tong=0
for i in N:
if i%2==0:
ssh+=1
tong+=i
soluong=0
for i in range (0,len(N)):
if i>(tong/ssh):
soluong+=1
with open("[Link]", "w") as f:
[Link](str(soluong)+" "+str("{:.3f}".format(tong))
015TD05. Phần tử bằng 2k. Có: vị trí max. Không: -1 số phần tử >=k
with open("[Link]", "r") as f:
data = [Link]()
arr = list(map(int, data[0].split()))
k = int(data[1].strip())
position = -1
count_gte_k = 0
for idx, value in enumerate(arr):
if value >= k:
count_gte_k += 1
if value == 2 * k:
position = idx + 1
with open("[Link]", "w") as f:
[Link](f"{position} {count_gte_k}\n")