<?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=0197_-_Combinari</id>
	<title>0197 - Combinari - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=0197_-_Combinari"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0197_-_Combinari&amp;action=history"/>
	<updated>2026-05-01T16:01:58Z</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=0197_-_Combinari&amp;diff=7646&amp;oldid=prev</id>
		<title>Gabii: Pagină nouă: = Cerinţa = Se citesc două numere naturale nenule &lt;code&gt;n&lt;/code&gt; și &lt;code&gt;k&lt;/code&gt;. Să se afişeze, în ordine lexicografică, submulțimile de câte &lt;code&gt;k&lt;/code&gt; elemente ale mulţimii &lt;code&gt;{1,2,..,n}&lt;/code&gt;.  = Date de intrare = Fişierul de intrare &lt;code&gt;combinariIN.txt&lt;/code&gt; conţine pe prima linie numerele &lt;code&gt;n&lt;/code&gt; și &lt;code&gt;k&lt;/code&gt;, separate printr-un spatiu.  = Date de ieşire = Fişierul de ieşire &lt;code&gt;combinariOUT.txt&lt;/code&gt; va conţine pe fiecare li...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0197_-_Combinari&amp;diff=7646&amp;oldid=prev"/>
		<updated>2023-12-04T18:43:25Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: = Cerinţa = Se citesc două numere naturale nenule &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;. Să se afişeze, în ordine lexicografică, submulțimile de câte &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt; elemente ale mulţimii &amp;lt;code&amp;gt;{1,2,..,n}&amp;lt;/code&amp;gt;.  = Date de intrare = Fişierul de intrare &amp;lt;code&amp;gt;combinariIN.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;k&amp;lt;/code&amp;gt;, separate printr-un spatiu.  = Date de ieşire = Fişierul de ieşire &amp;lt;code&amp;gt;combinariOUT.txt&amp;lt;/code&amp;gt; va conţine pe fiecare li...&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 citesc două numere naturale nenule &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;. Să se afişeze, în ordine lexicografică, submulțimile de câte &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt; elemente ale mulţimii &amp;lt;code&amp;gt;{1,2,..,n}&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fişierul de intrare &amp;lt;code&amp;gt;combinariIN.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;k&amp;lt;/code&amp;gt;, separate printr-un spatiu.&lt;br /&gt;
&lt;br /&gt;
= Date de ieşire =&lt;br /&gt;
Fişierul de ieşire &amp;lt;code&amp;gt;combinariOUT.txt&amp;lt;/code&amp;gt; va conţine pe fiecare linie câte &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt; valori, separate prin câte un spaţiu, reprezentând elementele unei submulțimi.&lt;br /&gt;
&lt;br /&gt;
= Restricţii şi precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ k ≤ n ≤ 15&amp;lt;/code&amp;gt;&lt;br /&gt;
* elementele fiecărei submulţimi vor fi afişate în ordine crescătoare&lt;br /&gt;
&lt;br /&gt;
= Exemplul 1 =&lt;br /&gt;
&amp;lt;code&amp;gt;combinariIN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 4 2&lt;br /&gt;
&amp;lt;code&amp;gt;combinariOUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 1 2 &lt;br /&gt;
 1 3 &lt;br /&gt;
 1 4 &lt;br /&gt;
 2 3 &lt;br /&gt;
 2 4 &lt;br /&gt;
 3 4 &lt;br /&gt;
&lt;br /&gt;
= Exemplul 2 =&lt;br /&gt;
&amp;lt;code&amp;gt;combinariIN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 4 2&lt;br /&gt;
consola &lt;br /&gt;
 &amp;quot;Nu corespunde restricțiilor&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 generate_combinations(n, k, current_combination, start, result):&lt;br /&gt;
    if k == 0:&lt;br /&gt;
        result.append(current_combination[:])&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    for i in range(start, n + 1):&lt;br /&gt;
        current_combination.append(i)&lt;br /&gt;
        generate_combinations(n, k - 1, current_combination, i + 1, result)&lt;br /&gt;
        current_combination.pop()&lt;br /&gt;
&lt;br /&gt;
def generate_and_write_combinations(input_file, output_file):&lt;br /&gt;
    try:&lt;br /&gt;
        with open(input_file, &amp;#039;r&amp;#039;) as file:&lt;br /&gt;
            n, k = map(int, file.readline().split())&lt;br /&gt;
&lt;br /&gt;
        if not (1 &amp;lt;= k &amp;lt;= n &amp;lt;= 15):&lt;br /&gt;
            raise ValueError(&amp;quot;Nu corespunde restricțiilor&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        result = []&lt;br /&gt;
        generate_combinations(n, k, [], 1, result)&lt;br /&gt;
&lt;br /&gt;
        with open(output_file, &amp;#039;w&amp;#039;) as file:&lt;br /&gt;
            for combination in result:&lt;br /&gt;
                file.write(&amp;#039; &amp;#039;.join(map(str, combination)) + &amp;#039;\n&amp;#039;)&lt;br /&gt;
    except ValueError as e:&lt;br /&gt;
        with open(output_file, &amp;#039;w&amp;#039;) as file:&lt;br /&gt;
            file.write(str(e) + &amp;#039;\n&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    generate_and_write_combinations(&amp;quot;combinariIN.txt&amp;quot;, &amp;quot;combinariOUT.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gabii</name></author>
	</entry>
</feed>