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
1277 - ProdusCartezian1
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!
= Cerinţa = Se dau două numere naturale nenule <code>n</code> și <code>m</code>. Considerăm mulțimea <code>A={1,2,..,n}</code>. Să se genereze în ordine lexicografică elementele produsului cartezian . = Date de intrare = Fișierul de intrare <code>produscartezian1IN.txt</code> conține pe prima linie numerele <code>n</code> și <code>m</code>, separate printr-un spațiu. = Date de ieşire = Fișierul de ieșire <code>produscartezian1OUT.txt</code> va conține elementele produsului cartezian, fiecare pe o linie. Valorile de pe fiecare linie vor fi separate prin câte un spațiu. În cazul în care restricțiile nu sunt îndeplinite, se va afișa mesajul "Datele nu corespund restrictiilor impuse". = Restricţii şi precizări = * <code>1 ≤ n ≤ 7</code> * <code>1 ≤ m ≤ 6</code> = Exemplul 1: = <code>produscartezian1IN.txt</code> 2 3 <code>produscartezian1OUT.txt</code> 1 1 1 1 1 2 1 2 1 1 2 2 2 1 1 2 1 2 2 2 1 2 2 2 = Exemplul 2: = <code>produscartezian1IN.txt</code> 2 8 <code>produscartezian1OUT.txt</code> Datele nu corespund restrictiilor impuse == Rezolvare == <syntaxhighlight lang="python" line="1"> def afisare(x, m, out_file): with open(out_file, 'a') as f: for i in range(1, m + 1): f.write(f"{x[i]} ") f.write("\n") def bectreching(k, n, m, x, out_file): for i in range(1, n + 1): x[k] = i if k < m: bectreching(k + 1, n, m, x, out_file) else: afisare(x, m, out_file) def verifica_restrictii(n, m): if 1 <= n <= 7 and 1 <= m <= 6: return True else: return False def main(): with open("produscartezian1IN.txt", 'r') as infile: n, m = map(int, infile.readline().strip().split()) if verifica_restrictii(n, m): x = [0] * (m + 1) out_file = "produscartezian1OUT.txt" with open(out_file, 'w'): # Clear the output file pass bectreching(1, n, m, x, out_file) else: with open("produscartezian1OUT.txt", 'w') as outfile: outfile.write("Datele nu corespund restrictiilor impuse\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