Ответ:
1.Одномерный массив – это именованная последовательность, состоящая из пронумерованных элементов одного типа.
i. Prime = ['string1', 'string2', 'string3']
Prime[1] = 'string2'; //true
2.i. Word = input()
count = 0
flag = 0
for i in range(len(word)):
if word[i] != ' ' and flag == 0:
count += 1
flag = 1
else:
if word[i] == ' ':
print(count)
ii. ?
3. n, m = [int(i) for i in input().split()]
a = [[int(j) for j in input().split()] for i in range(n)]
best_i, best_j = 0, 0
curr_max = a[0][0]
for i in range(n):
for j in range(m):
if a[i][j] > curr_max:
curr_max = a[i][j]
best_i, best_j = i, j
print(best_i, best_j)
4. def swap_columns(a, i, j):
for k in range(len(a)):
a[k][i], a[k][j] = a[k][j], a[k][i]
n, m = [int(i) for i in input().split()]
i, j = [int(i) for i in input().split()]
swap_columns(a, i, j)
print('\n'.join([' '.join([str(i) for i in row]) for row in a]))
Объяснение:
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Ответ:
1.Одномерный массив – это именованная последовательность, состоящая из пронумерованных элементов одного типа.
i. Prime = ['string1', 'string2', 'string3']
Prime[1] = 'string2'; //true
2.i. Word = input()
count = 0
flag = 0
for i in range(len(word)):
if word[i] != ' ' and flag == 0:
count += 1
flag = 1
else:
if word[i] == ' ':
flag = 0
print(count)
ii. ?
3. n, m = [int(i) for i in input().split()]
a = [[int(j) for j in input().split()] for i in range(n)]
best_i, best_j = 0, 0
curr_max = a[0][0]
for i in range(n):
for j in range(m):
if a[i][j] > curr_max:
curr_max = a[i][j]
best_i, best_j = i, j
print(best_i, best_j)
4. def swap_columns(a, i, j):
for k in range(len(a)):
a[k][i], a[k][j] = a[k][j], a[k][i]
n, m = [int(i) for i in input().split()]
a = [[int(j) for j in input().split()] for i in range(n)]
i, j = [int(i) for i in input().split()]
swap_columns(a, i, j)
print('\n'.join([' '.join([str(i) for i in row]) for row in a]))
Объяснение: