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
3370 - Amedie
(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> #3370 - Amedie def valideaza_input(n, m, q, matrice, operatii): if not (2 <= n <= 800) or not (2 <= m <= 800) or not (0 < q <= 2000): return False for rand in matrice: if len(rand) != m or any(not(0 < int(elem) < 100001) for elem in rand): return False for op in operatii: if op[0] == 'L': if not (1 <= int(op[1]) <= n): return False elif op[0] == 'C': if not (1 <= int(op[1]) <= m): return False return True def calculeaza_mediana(matrice): amedie = sorted([elem for rand in matrice for elem in rand]) mijloc = len(amedie) // 2 if len(amedie) % 2 == 1: return amedie[mijloc] else: return min(amedie[mijloc - 1], amedie[mijloc]) def aplica_operatii(matrice, operatii): rezultate = [] for op in operatii: if op[0] == 'L': del matrice[int(op[1]) - 1] elif op[0] == 'C': for rand in matrice: del rand[int(op[1]) - 1] elif op[0] == 'Q': rezultate.append(calculeaza_mediana(matrice)) return rezultate def main(): with open('amediein.txt', 'r') as infile: n, m, q = map(int, infile.readline().split()) matrice = [list(map(int, infile.readline().split())) for _ in range(n)] operatii = [linie.strip().split() for linie in infile] if valideaza_input(n, m, q, matrice, operatii): print("Datele de intrare corespund restricțiilor impuse") rezultate = aplica_operatii(matrice, operatii) with open('amedieout.txt', 'w') as outfile: for rezultat in rezultate: outfile.write(str(rezultat) + '\n') else: print("Datele de intrare NU corespund restricțiilor impuse") 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