Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import *
- def matrixGeneration():
- ''' Генерируется матрица согласно условию '''
- global answer, M, N
- N = randint(0, 1000)
- M = randint(-1000000, 1000000)
- for x in range(N):
- matrix.append([randint(-1000000, 1000000) for i in range(N)])
- # матрица записывается в файл
- f = open("in-6.txt", "w")
- f.write(str(matrix))
- f.close()
- def openFileAndReadData():
- global answer
- data = []
- with open("in-6.txt") as f:
- for line in f:
- data.append([int(x) for x in line.replace("[", "").replace("]", "").replace(",", "").split()])
- f.close()
- skip = 0
- per = 0
- tmp = 0
- for array in data:
- for x in array:
- try: x = int(x)
- except ValueError: continue # Если символ не цифра, то пропускается
- # print ("x =", x)
- per += 1
- if not per%2 and not tmp:
- per = 1
- tmp = skip
- skip += 1
- break
- if x > M and not tmp:
- answer += 1;
- tmp -= 1
- print (f'N: {N}\nM: {M}\nanswer: {answer}')
- matrix = []
- answer = 0
- matrixGeneration() # Создаётся матрица
- openFileAndReadData() # Работа с матрицей
Advertisement
Add Comment
Please, Sign In to add comment