Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
1800 - Matop
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Rezolvare== <syntaxhighlight lang="python" line="1"> #1800 matop def execute_operations(N, K, operations): matrix = [[0] * N for _ in range(N)] diagonal_sum = 0 output = [] for op in operations: op_type, *args = op if op_type == 1: lin, val = args for j in range(N): matrix[lin - 1][j] = max(matrix[lin - 1][j], val) elif op_type == 2: col, val = args for i in range(N): matrix[i][col - 1] = max(matrix[i][col - 1], val) elif op_type == 3: lin, col = args output.append(matrix[lin - 1][col - 1]) elif op_type == 4: diagonal_sum += sum(matrix[i][i] for i in range(N)) if diagonal_sum: output.append(diagonal_sum) # Scrierea rezultatelor în fișierul 'matop.out' with open('matop.out', 'w') as file_out: for result in output: file_out.write(str(result) + '\n') def validate_input(N, K, operations): if not isinstance(N, int) or not isinstance(K, int) or not (1 <= N <= 1000) or not (1 <= K <= 1000): return False, "Numerele N și K trebuie să fie întregi între 1 și 1000." if not isinstance(operations, list) or not all(isinstance(op, list) and len(op) >= 1 for op in operations): return False, "Lista de operații trebuie să fie o listă de liste cu cel puțin un element." return True, None def main(): try: # Citirea datelor de intrare din fișierul 'matop.in' with open('matop.in', 'r') as file: N, K = map(int, file.readline().split()) operations = [list(map(int, line.split())) for line in file.readlines()] except (ValueError, FileNotFoundError): print("Date de intrare invalide sau fișierul nu există.") return is_valid, error_message = validate_input(N, K, operations) if not is_valid: print("Date de intrare invalide:", error_message) return # Executarea operațiilor și afișarea rezultatelor în fișierul 'matop.out' execute_operations(N, K, operations) if __name__ == "__main__": main() </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width