<?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=0320_-_Partitii_Numar</id>
	<title>0320 - Partitii Numar - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=0320_-_Partitii_Numar"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0320_-_Partitii_Numar&amp;action=history"/>
	<updated>2026-05-01T06:34:15Z</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=0320_-_Partitii_Numar&amp;diff=8966&amp;oldid=prev</id>
		<title>Rus Marius: Pagină nouă: = Cerinţa = Se dă un număr natural &lt;code&gt;n&lt;/code&gt;. Determinaţi, în ordine lexicografică, toate modalităţile de a-l scrie pe &lt;code&gt;n&lt;/code&gt; ca sumă de numere naturale.  = Date de intrare = Fişierul de intrare &lt;code&gt;partitiinumarIN.txt&lt;/code&gt; conţine pe prima linie numărul &lt;code&gt;n&lt;/code&gt;.  = Date de ieşire = Fişierul de ieşire &lt;code&gt;partitiinumarOUT.txt&lt;/code&gt; va conţine pe fiecare linie câte un şir de numere naturale ordonate crescător, separate prin câte u...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0320_-_Partitii_Numar&amp;diff=8966&amp;oldid=prev"/>
		<updated>2024-01-04T13:19:51Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: = Cerinţa = Se dă un număr natural &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;. Determinaţi, în ordine lexicografică, toate modalităţile de a-l scrie pe &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; ca sumă de numere naturale.  = Date de intrare = Fişierul de intrare &amp;lt;code&amp;gt;partitiinumarIN.txt&amp;lt;/code&amp;gt; conţine pe prima linie numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;.  = Date de ieşire = Fişierul de ieşire &amp;lt;code&amp;gt;partitiinumarOUT.txt&amp;lt;/code&amp;gt; va conţine pe fiecare linie câte un şir de numere naturale ordonate crescător, separate prin câte u...&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 dă un număr natural &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;. Determinaţi, în ordine lexicografică, toate modalităţile de a-l scrie pe &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; ca sumă de numere naturale.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fişierul de intrare &amp;lt;code&amp;gt;partitiinumarIN.txt&amp;lt;/code&amp;gt; conţine pe prima linie numărul &amp;lt;code&amp;gt;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;partitiinumarOUT.txt&amp;lt;/code&amp;gt; va conţine pe fiecare linie câte un şir de numere naturale ordonate crescător, separate prin câte un spaţiu. Suma numerelor din fiecare şir este &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;. Şirurile vor fi afişate în ordine lexicografică.În cazul în care restricțiile nu sunt îndeplinite, se va afișa mesajul &amp;quot;Nu corespunde restricțiilor 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 ≤ 40&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Exemplul 1: =&lt;br /&gt;
&amp;lt;code&amp;gt;partitiinumarIN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 5&lt;br /&gt;
&amp;lt;code&amp;gt;partitiinumarOUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 1 1 1 1 1 &lt;br /&gt;
 1 1 1 2 &lt;br /&gt;
 1 1 3 &lt;br /&gt;
 1 2 2 &lt;br /&gt;
 1 4 &lt;br /&gt;
 2 3 &lt;br /&gt;
 5 &lt;br /&gt;
&lt;br /&gt;
= Exemplul 2: =&lt;br /&gt;
&amp;lt;code&amp;gt;partitiinumarIN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 41&lt;br /&gt;
&amp;lt;code&amp;gt;partitiinumarOUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;quot;Datele nu corespund restrictiilor impuse&amp;quot;&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 check_restrictions(n):&lt;br /&gt;
    return 1 &amp;lt;= n &amp;lt;= 40&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def generate_partitions(n, current_partition, all_partitions):&lt;br /&gt;
    if n == 0:&lt;br /&gt;
        all_partitions.append(list(current_partition))&lt;br /&gt;
        return&lt;br /&gt;
    for i in range(1, n + 1):&lt;br /&gt;
        if not current_partition or i &amp;gt;= current_partition[-1]:&lt;br /&gt;
            current_partition.append(i)&lt;br /&gt;
            generate_partitions(n - i, current_partition, all_partitions)&lt;br /&gt;
            current_partition.pop()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def write_partitions_to_file(partitions, output_file):&lt;br /&gt;
    with open(output_file, &amp;#039;w&amp;#039;) as file:&lt;br /&gt;
        for partition in partitions:&lt;br /&gt;
            partition_str = &amp;#039; &amp;#039;.join(map(str, partition))&lt;br /&gt;
            file.write(partition_str + &amp;#039;\n&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def process_input(input_file, output_file):&lt;br /&gt;
    with open(input_file, &amp;#039;r&amp;#039;) as file:&lt;br /&gt;
        n = int(file.readline().strip())&lt;br /&gt;
&lt;br /&gt;
    if not check_restrictions(n):&lt;br /&gt;
        with open(output_file, &amp;#039;w&amp;#039;) as file:&lt;br /&gt;
            file.write(&amp;quot;Datele nu corespund restrictiilor impuse\n&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        all_partitions = []&lt;br /&gt;
        generate_partitions(n, [], all_partitions)&lt;br /&gt;
        all_partitions.sort()&lt;br /&gt;
        write_partitions_to_file(all_partitions, output_file)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    input_file = &amp;quot;partitiinumarIN.txt&amp;quot;&lt;br /&gt;
    output_file = &amp;quot;partitiinumarOUT.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    process_input(input_file, output_file)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rus Marius</name></author>
	</entry>
</feed>