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
0597 - Poza
(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> def citeste_poza(): try: n, m = map(int, input("Introduceți numărul de linii și coloane (1 ≤ n,m ≤ 100): ").split()) # Verificăm dacă dimensiunile respectă restricțiile if not (1 <= n <= 100 and 1 <= m <= 100): raise ValueError("Datele de intrare nu corespund restricțiilor impuse.") poza = [] prim_plan_gasit = False for i in range(n): linie = list(map(int, input().split())) # Verificăm dacă există cel puțin un element de prim-plan if 1 in linie: prim_plan_gasit = True poza.append(linie) # Dacă nu există elemente de prim-plan, afisam o excepție if not prim_plan_gasit: raise ValueError("În poză trebuie să existe cel puțin un element de prim-plan.") print("Datele de intrare corespund restricțiilor impuse.") return poza except ValueError as ve: print(ve) exit() def taie_poza(poza): min_linie, max_linie, min_coloana, max_coloana = n, 0, m, 0 for i in range(n): for j in range(m): if poza[i][j] == 1: min_linie = min(min_linie, i) max_linie = max(max_linie, i) min_coloana = min(min_coloana, j) max_coloana = max(max_coloana, j) p = max_linie - min_linie + 1 q = max_coloana - min_coloana + 1 poza_taiata = [poza[i][min_coloana:max_coloana + 1] for i in range(min_linie, max_linie + 1)] return p, q, poza_taiata if __name__ == "__main__": poza = citeste_poza() n, m = len(poza), len(poza[0]) p, q, poza_taiata = taie_poza(poza) print(p, q) for linie in poza_taiata: print(*linie) </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