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
2460 - multimi5https:/wiki.universitas.ro/wiki/2460 - multimi5
(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!
= Exemplul 1: = <code>multimi5IN.txt</code> 3 A=2-8/2 C=11-23/3 B=4-16/4 A*(B+C) <code>multimi5OUT.txt</code> 2 4 8 === Explicație === Mulțimile au următoarele elemente: <code>A={2, 4, 6, 8}</code> <code>B={4, 8,12, 16}</code> <code>C={11, 14, 17, 20, 23}</code> Efectuând operațiile obținem: <code>B+C = {4, 8, 11, 12, 14, 16, 17, 20, 23}</code> și <code>A*(B+C) = {4, 8}</code> == Exemplul 2: == <code>multimi5.in</code> 17 A=2-8/2 C=11-23/3 B=4-16/4 A*(B+C) <code>multimi5.out</code> Datele nu corespund restrictiilor impuse == Rezolvare: == <syntaxhighlight lang="python3" line="1"> def parseaza_set(linie): parti = linie.split('=') if len(parti) != 2: return None _, definitie_interval = parti inceput, rest = definitie_interval.split('-') sfarsit, pas = rest.split('/') return set(range(int(inceput), int(sfarsit) + 1, int(pas))) def verifica_restricții(n, seturi, expresie): if not (1 < n <= 16): return False for set in seturi.values(): if set is None or not all(0 <= elem <= 1000000000 for elem in set) or len(set) > 10000: return False if not (3 <= len(expresie) <= 1000): return False return True def evalueaza_expresie(A, B, C): return A.intersection(B.union(C)) def main(): with open("multimi5IN.txt", "r") as fin: n = int(fin.readline().strip()) seturi = {} for _ in range(n): linie = fin.readline().strip() set_nume = linie[0] set = parseaza_set(linie) if set is None: with open("multimi5OUT.txt", "w") as fout: fout.write("Datele nu corespund restrictiilor impuse\n") return seturi[set_nume] = set expresie = fin.readline().strip() if not verifica_restricții(n, seturi, expresie): with open("multimi5OUT.txt", "w") as fout: fout.write("Datele nu corespund restrictiilor impuse\n") return A, B, C = seturi['A'], seturi['B'], seturi['C'] rezultat = evalueaza_expresie(A, B, C) with open("multimi5OUT.txt", "w") as fout: fout.write(f"{len(rezultat)}\n") for element in sorted(rezultat): fout.write(f"{element} ") fout.write("\n") 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