Last active
August 13, 2021 13:33
-
-
Save bas-kirill/70820bde352df75ac30887cd00222fd6 to your computer and use it in GitHub Desktop.
Бас Кирилл. Задание по информатике
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ListNode: | |
def __init__(self, x): | |
self.val = x | |
self.next = None | |
def reverseList(head: ListNode) -> ListNode: | |
previous = None | |
current = head | |
while current: | |
n = current.next | |
current.next = previous | |
previous = current | |
current = n | |
return previous |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getAdjMatrix(matrix, file_name): | |
with open(file_name) as input_file: | |
for line in input_file.readlines(): | |
matrix.append(list(map(int, line.split()))) | |
def transformToIncMatrix(adj_matrix): | |
inc_matrix = [] | |
num_of_vertexes = len(adj_matrix) | |
for i in range(num_of_vertexes): | |
for j in range(i, num_of_vertexes): | |
if adj_matrix[i][j]: | |
tmp_line = [0 for _ignr in range(num_of_vertexes)] | |
tmp_line[i] = tmp_line[j] = 1 | |
inc_matrix.append(tmp_line) | |
return inc_matrix | |
def main(): | |
file_name = 'file1.txt' | |
adj_matrix = [] | |
getAdjMatrix(adj_matrix, file_name) | |
inc_matrix = transformToIncMatrix(adj_matrix) | |
print(*inc_matrix, sep='\n') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment