<?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=1278_-_ProdusCartezian2</id>
	<title>1278 - ProdusCartezian2 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=1278_-_ProdusCartezian2"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1278_-_ProdusCartezian2&amp;action=history"/>
	<updated>2026-05-01T09:03:01Z</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=1278_-_ProdusCartezian2&amp;diff=9822&amp;oldid=prev</id>
		<title>Oros Ioana Diana: Pagină nouă: = Cerinţa = Se dau &lt;code&gt;n&lt;/code&gt; mulțimi:  * A1={1,2,...,v1} * A2={1,2,...,v2} * .. * An={1,2,...,vn}  Să se genereze în ordine lexicografică elementele produsului cartezian .  = Date de intrare = Fișierul de intrare &lt;code&gt;produscartezian2IN.txt&lt;/code&gt; conține pe prima linie numărul &lt;code&gt;n&lt;/code&gt;, iar pe a doua linie &lt;code&gt;n&lt;/code&gt; numere naturale nenule &lt;code&gt;v[1] v[2] ... v[n]&lt;/code&gt;.  = Date de ieşire = Fișierul de ieșire &lt;code&gt;produscartezian2OUt.txt&lt;/code&gt; v...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1278_-_ProdusCartezian2&amp;diff=9822&amp;oldid=prev"/>
		<updated>2024-05-18T19:25:33Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: = Cerinţa = Se dau &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; mulțimi:  * A1={1,2,...,v1} * A2={1,2,...,v2} * .. * An={1,2,...,vn}  Să se genereze în ordine lexicografică elementele produsului cartezian .  = Date de intrare = Fișierul de intrare &amp;lt;code&amp;gt;produscartezian2IN.txt&amp;lt;/code&amp;gt; conține pe prima linie numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, iar pe a doua linie &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere naturale nenule &amp;lt;code&amp;gt;v[1] v[2] ... v[n]&amp;lt;/code&amp;gt;.  = Date de ieşire = Fișierul de ieșire &amp;lt;code&amp;gt;produscartezian2OUt.txt&amp;lt;/code&amp;gt; v...&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 &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; mulțimi:&lt;br /&gt;
&lt;br /&gt;
* A1={1,2,...,v1}&lt;br /&gt;
* A2={1,2,...,v2}&lt;br /&gt;
* ..&lt;br /&gt;
* An={1,2,...,vn}&lt;br /&gt;
&lt;br /&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;produscartezian2IN.txt&amp;lt;/code&amp;gt; conține pe prima linie numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, iar pe a doua linie &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere naturale nenule &amp;lt;code&amp;gt;v[1] v[2] ... v[n]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Date de ieşire =&lt;br /&gt;
Fișierul de ieșire &amp;lt;code&amp;gt;produscartezian2OUt.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 ≤ v[i] ≤ 7&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Exemplul 1: =&lt;br /&gt;
&amp;lt;code&amp;gt;produscartezian2IN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 3&lt;br /&gt;
 2 1 3&lt;br /&gt;
&amp;lt;code&amp;gt;produscartezian2OUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 1 1 1 &lt;br /&gt;
 1 1 2 &lt;br /&gt;
 1 1 3 &lt;br /&gt;
 2 1 1 &lt;br /&gt;
 2 1 2 &lt;br /&gt;
 2 1 3 &lt;br /&gt;
&lt;br /&gt;
= Exemplul 2: =&lt;br /&gt;
&amp;lt;code&amp;gt;produscartezian2IN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 10&lt;br /&gt;
 2 1 3&lt;br /&gt;
&amp;lt;code&amp;gt;produscartezian2OUT.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 citire():&lt;br /&gt;
    with open(&amp;quot;produscartezian2IN.txt&amp;quot;, &amp;quot;r&amp;quot;) as fin:&lt;br /&gt;
        n = int(fin.readline().strip())&lt;br /&gt;
        v = list(map(int, fin.readline().strip().split()))&lt;br /&gt;
    return n, v&lt;br /&gt;
&lt;br /&gt;
def afisare(x, fout):&lt;br /&gt;
    fout.write(&amp;quot; &amp;quot;.join(map(str, x)) + &amp;#039;\n&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
def backtracking(k, n, v, x, fout):&lt;br /&gt;
    if k &amp;gt; n:&lt;br /&gt;
        afisare(x, fout)&lt;br /&gt;
    else:&lt;br /&gt;
        for i in range(1, v[k-1] + 1):&lt;br /&gt;
            x[k-1] = i&lt;br /&gt;
            backtracking(k + 1, n, v, x, fout)&lt;br /&gt;
&lt;br /&gt;
def verifica_restrictii(n, v):&lt;br /&gt;
    if 1 &amp;lt;= n &amp;lt;= 7 and all(1 &amp;lt;= vi &amp;lt;= 7 for vi in v):&lt;br /&gt;
        return True&lt;br /&gt;
    return False&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    n, v = citire()&lt;br /&gt;
    with open(&amp;quot;produscartezian2OUT.txt&amp;quot;, &amp;quot;w&amp;quot;) as fout:&lt;br /&gt;
        if verifica_restrictii(n, v):&lt;br /&gt;
            x = [0] * n&lt;br /&gt;
            backtracking(1, n, v, x, fout)&lt;br /&gt;
        else:&lt;br /&gt;
            fout.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>