<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=1277_-_ProdusCartezian1</id>
	<title>1277 - ProdusCartezian1 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=1277_-_ProdusCartezian1"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1277_-_ProdusCartezian1&amp;action=history"/>
	<updated>2026-05-01T06:40:28Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.universitas.ro/index.php?title=1277_-_ProdusCartezian1&amp;diff=9821&amp;oldid=prev</id>
		<title>Oros Ioana Diana: Pagină nouă: = Cerinţa = Se dau două numere naturale nenule &lt;code&gt;n&lt;/code&gt; și &lt;code&gt;m&lt;/code&gt;. Considerăm mulțimea &lt;code&gt;A={1,2,..,n}&lt;/code&gt;. Să se genereze în ordine lexicografică elementele produsului cartezian .  = Date de intrare = Fișierul de intrare &lt;code&gt;produscartezian1IN.txt&lt;/code&gt; conține pe prima linie numerele &lt;code&gt;n&lt;/code&gt; și &lt;code&gt;m&lt;/code&gt;, separate printr-un spațiu.  = Date de ieşire = Fișierul de ieșire &lt;code&gt;produscartezian1OUT.txt&lt;/code&gt; va conține elemen...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1277_-_ProdusCartezian1&amp;diff=9821&amp;oldid=prev"/>
		<updated>2024-05-18T19:18:57Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: = Cerinţa = Se dau două numere naturale nenule &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt;. Considerăm mulțimea &amp;lt;code&amp;gt;A={1,2,..,n}&amp;lt;/code&amp;gt;. Să se genereze în ordine lexicografică elementele produsului cartezian .  = Date de intrare = Fișierul de intrare &amp;lt;code&amp;gt;produscartezian1IN.txt&amp;lt;/code&amp;gt; conține pe prima linie numerele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt;, separate printr-un spațiu.  = Date de ieşire = Fișierul de ieșire &amp;lt;code&amp;gt;produscartezian1OUT.txt&amp;lt;/code&amp;gt; va conține elemen...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Cerinţa =&lt;br /&gt;
Se dau două numere naturale nenule &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt;. Considerăm mulțimea &amp;lt;code&amp;gt;A={1,2,..,n}&amp;lt;/code&amp;gt;. Să se genereze în ordine lexicografică elementele produsului cartezian .&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fișierul de intrare &amp;lt;code&amp;gt;produscartezian1IN.txt&amp;lt;/code&amp;gt; conține pe prima linie numerele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt;, separate printr-un spațiu.&lt;br /&gt;
&lt;br /&gt;
= Date de ieşire =&lt;br /&gt;
Fișierul de ieșire &amp;lt;code&amp;gt;produscartezian1OUT.txt&amp;lt;/code&amp;gt; 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 &amp;quot;Datele nu corespund restrictiilor impuse&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= Restricţii şi precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ n ≤ 7&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ m ≤ 6&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Exemplul 1: =&lt;br /&gt;
&amp;lt;code&amp;gt;produscartezian1IN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 2 3&lt;br /&gt;
&amp;lt;code&amp;gt;produscartezian1OUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 1 1 1 &lt;br /&gt;
 1 1 2 &lt;br /&gt;
 1 2 1 &lt;br /&gt;
 1 2 2 &lt;br /&gt;
 2 1 1 &lt;br /&gt;
 2 1 2 &lt;br /&gt;
 2 2 1 &lt;br /&gt;
 2 2 2 &lt;br /&gt;
&lt;br /&gt;
= Exemplul 2: =&lt;br /&gt;
&amp;lt;code&amp;gt;produscartezian1IN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 2 8&lt;br /&gt;
&amp;lt;code&amp;gt;produscartezian1OUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 Datele nu corespund restrictiilor impuse&lt;br /&gt;
&lt;br /&gt;
== Rezolvare ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
def afisare(x, m, out_file):&lt;br /&gt;
    with open(out_file, &amp;#039;a&amp;#039;) as f:&lt;br /&gt;
        for i in range(1, m + 1):&lt;br /&gt;
            f.write(f&amp;quot;{x[i]} &amp;quot;)&lt;br /&gt;
        f.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
def bectreching(k, n, m, x, out_file):&lt;br /&gt;
    for i in range(1, n + 1):&lt;br /&gt;
        x[k] = i&lt;br /&gt;
        if k &amp;lt; m:&lt;br /&gt;
            bectreching(k + 1, n, m, x, out_file)&lt;br /&gt;
        else:&lt;br /&gt;
            afisare(x, m, out_file)&lt;br /&gt;
&lt;br /&gt;
def verifica_restrictii(n, m):&lt;br /&gt;
    if 1 &amp;lt;= n &amp;lt;= 7 and 1 &amp;lt;= m &amp;lt;= 6:&lt;br /&gt;
        return True&lt;br /&gt;
    else:&lt;br /&gt;
        return False&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    with open(&amp;quot;produscartezian1IN.txt&amp;quot;, &amp;#039;r&amp;#039;) as infile:&lt;br /&gt;
        n, m = map(int, infile.readline().strip().split())&lt;br /&gt;
&lt;br /&gt;
    if verifica_restrictii(n, m):&lt;br /&gt;
        x = [0] * (m + 1)&lt;br /&gt;
        out_file = &amp;quot;produscartezian1OUT.txt&amp;quot;&lt;br /&gt;
        with open(out_file, &amp;#039;w&amp;#039;):  # Clear the output file&lt;br /&gt;
            pass&lt;br /&gt;
        bectreching(1, n, m, x, out_file)&lt;br /&gt;
    else:&lt;br /&gt;
        with open(&amp;quot;produscartezian1OUT.txt&amp;quot;, &amp;#039;w&amp;#039;) as outfile:&lt;br /&gt;
            outfile.write(&amp;quot;Datele nu corespund restrictiilor impuse\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    main()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Oros Ioana Diana</name></author>
	</entry>
</feed>