<?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=0125_-_Permutari2</id>
	<title>0125 - Permutari2 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=0125_-_Permutari2"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0125_-_Permutari2&amp;action=history"/>
	<updated>2026-05-01T17:10:35Z</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=0125_-_Permutari2&amp;diff=7600&amp;oldid=prev</id>
		<title>Gabii: Pagină nouă: = Cerinţa = Se citeşte un număr natural nenul &lt;code&gt;n&lt;/code&gt;, apoi &lt;code&gt;n&lt;/code&gt; numere naturale distincte. Să se afişeze, în ordine lexicografică, permutările mulţimii formate din cele &lt;code&gt;n&lt;/code&gt; numere citite.  = Date de intrare = Fişierul de intrare &lt;code&gt;permutari2IN.txt&lt;/code&gt; conţine pe prima linie numărul &lt;code&gt;n&lt;/code&gt;, ia r pe a doua linie &lt;code&gt;n&lt;/code&gt; numere naturale.  = Date de ieşire = Fişierul de ieşire &lt;code&gt;permutari2OUT.txt&lt;/code&gt; va con...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0125_-_Permutari2&amp;diff=7600&amp;oldid=prev"/>
		<updated>2023-12-03T20:50:11Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: = Cerinţa = Se citeşte un număr natural nenul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, apoi &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere naturale distincte. Să se afişeze, în ordine lexicografică, permutările mulţimii formate din cele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere citite.  = Date de intrare = Fişierul de intrare &amp;lt;code&amp;gt;permutari2IN.txt&amp;lt;/code&amp;gt; conţine pe prima linie numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, ia r pe a doua linie &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere naturale.  = Date de ieşire = Fişierul de ieşire &amp;lt;code&amp;gt;permutari2OUT.txt&amp;lt;/code&amp;gt; va con...&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 citeşte un număr natural nenul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, apoi &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere naturale distincte. Să se afişeze, în ordine lexicografică, permutările mulţimii formate din cele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere citite.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fişierul de intrare &amp;lt;code&amp;gt;permutari2IN.txt&amp;lt;/code&amp;gt; conţine pe prima linie numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, ia r pe a doua linie &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere naturale.&lt;br /&gt;
&lt;br /&gt;
= Date de ieşire =&lt;br /&gt;
Fişierul de ieşire &amp;lt;code&amp;gt;permutari2OUT.txt&amp;lt;/code&amp;gt; va conţine pe fiecare linie elementele unei permutări, separate prin câte un spaţiu.&lt;br /&gt;
&lt;br /&gt;
= Restricţii şi precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;0 &amp;lt; n &amp;lt; 9&amp;lt;/code&amp;gt;&lt;br /&gt;
* cele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere de pe a doua linie a fişierului de intrare sunt mai mici decât &amp;lt;code&amp;gt;100&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Exemplu: =&lt;br /&gt;
&amp;lt;code&amp;gt;permutari2IN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 3&lt;br /&gt;
 4 7 3&lt;br /&gt;
&amp;lt;code&amp;gt;permutari2OUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 3 4 7 &lt;br /&gt;
 3 7 4 &lt;br /&gt;
 4 3 7 &lt;br /&gt;
 4 7 3 &lt;br /&gt;
 7 3 4 &lt;br /&gt;
 7 4 3 &lt;br /&gt;
&lt;br /&gt;
== Exemplul 2 ==&lt;br /&gt;
&amp;lt;code&amp;gt;permutari2IN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 10&lt;br /&gt;
 4 7 3&lt;br /&gt;
consola:&lt;br /&gt;
&lt;br /&gt;
Eroare: Numărul n trebuie să fie între 0 și 9.&lt;br /&gt;
&lt;br /&gt;
== Rezolvare ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
def verifica_restrictii(n, numere):&lt;br /&gt;
    if not (0 &amp;lt; n &amp;lt; 9):&lt;br /&gt;
        print(&amp;quot;Eroare: Numărul n trebuie să fie între 0 și 9.&amp;quot;)&lt;br /&gt;
        return False&lt;br /&gt;
&lt;br /&gt;
    if len(numere) != n or len(set(numere)) != n or any(x &amp;gt;= 100 for x in numere):&lt;br /&gt;
        print(&amp;quot;Eroare: Introduceți n numere naturale distincte mai mici decât 100.&amp;quot;)&lt;br /&gt;
        return False&lt;br /&gt;
&lt;br /&gt;
    return True&lt;br /&gt;
&lt;br /&gt;
def generate_permutations(n, current_permutation, numere, output_file):&lt;br /&gt;
    if len(current_permutation) == n:&lt;br /&gt;
        output_file.write(&amp;quot; &amp;quot;.join(map(str, current_permutation)) + &amp;quot;\n&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    for numar in sorted(numere):&lt;br /&gt;
        if numar not in current_permutation:&lt;br /&gt;
            generate_permutations(n, current_permutation + [numar], numere, output_file)&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    with open(&amp;quot;permutari2IN.txt&amp;quot;, &amp;quot;r&amp;quot;) as f:&lt;br /&gt;
        n = int(f.readline())&lt;br /&gt;
        numere = list(map(int, f.readline().split()))&lt;br /&gt;
&lt;br /&gt;
    if verifica_restrictii(n, numere):&lt;br /&gt;
        with open(&amp;quot;permutari2OUT.txt&amp;quot;, &amp;quot;w&amp;quot;) as output_file:&lt;br /&gt;
            generate_permutations(n, [], numere, output_file)&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>Gabii</name></author>
	</entry>
</feed>