<?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=0695_-_SumAll</id>
	<title>0695 - SumAll - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=0695_-_SumAll"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0695_-_SumAll&amp;action=history"/>
	<updated>2026-06-17T09:47:02Z</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=0695_-_SumAll&amp;diff=10111&amp;oldid=prev</id>
		<title>Danciu: Pagină nouă:  = Cerința = Fie &lt;code&gt;N&lt;/code&gt; un număr natural format din cifre nenule.  Să se determine suma tuturor numerelor distincte ce se pot forma cu toate cifrele numărului &lt;code&gt;N&lt;/code&gt;.  = Date de intrare = Fișierul de intrare &lt;code&gt;sumall.in&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;sumall.out&lt;/code&gt; va conţine pe prima linie suma tuturor numerelor distincte ce se pot forma cu toate cifrele numărului &lt;code&gt;N&lt;/...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0695_-_SumAll&amp;diff=10111&amp;oldid=prev"/>
		<updated>2024-06-04T08:42:34Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă:  = Cerința = Fie &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; un număr natural format din cifre nenule.  Să se determine suma tuturor numerelor distincte ce se pot forma cu toate cifrele numărului &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt;.  = Date de intrare = Fișierul de intrare &amp;lt;code&amp;gt;sumall.in&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;sumall.out&amp;lt;/code&amp;gt; va conţine pe prima linie suma tuturor numerelor distincte ce se pot forma cu toate cifrele numărului &amp;lt;code&amp;gt;N&amp;lt;/...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
= Cerința =&lt;br /&gt;
Fie &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; un număr natural format din cifre nenule.&lt;br /&gt;
&lt;br /&gt;
Să se determine suma tuturor numerelor distincte ce se pot forma cu toate cifrele numărului &amp;lt;code&amp;gt;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;sumall.in&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;sumall.out&amp;lt;/code&amp;gt; va conţine pe prima linie suma tuturor numerelor distincte ce se pot forma cu toate cifrele numărului &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt;.&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; 1019&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Exemplu: =&lt;br /&gt;
&amp;lt;code&amp;gt;sumall.in&amp;lt;/code&amp;gt;&lt;br /&gt;
 123&lt;br /&gt;
&amp;lt;code&amp;gt;sumall.out&amp;lt;/code&amp;gt;&lt;br /&gt;
 1332&lt;br /&gt;
&lt;br /&gt;
= Explicație =&lt;br /&gt;
Toate numerele distincte ce se pot forma cu cifrele &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt; sunt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;123&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;132&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;213&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;231&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;312&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;321&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;123 + 132 + 213 + 231 + 312 + 321 = 1332&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Exemplu: =&lt;br /&gt;
&amp;lt;code&amp;gt;sumall.in&amp;lt;/code&amp;gt;&lt;br /&gt;
 788&lt;br /&gt;
&amp;lt;code&amp;gt;sumall.out&amp;lt;/code&amp;gt;&lt;br /&gt;
 2553&lt;br /&gt;
&lt;br /&gt;
= Explicație =&lt;br /&gt;
Toate numerele distincte ce se pot forma cu cifrele &amp;lt;code&amp;gt;7&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;8&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;8&amp;lt;/code&amp;gt; sunt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;788&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;878&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;887&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;788 + 878 + 887 = 2553&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Rezolvare ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot;&amp;gt;&lt;br /&gt;
def generate_numbers(n, digits, used_digits, current_number, numbers):&lt;br /&gt;
    if len(current_number) == len(digits):&lt;br /&gt;
        numbers.append(int(current_number))&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    for digit in digits:&lt;br /&gt;
        if digit not in used_digits:&lt;br /&gt;
            used_digits[digit] = True&lt;br /&gt;
&lt;br /&gt;
            current_number += digit&lt;br /&gt;
&lt;br /&gt;
            generate_numbers(n, digits, used_digits, current_number, numbers)&lt;br /&gt;
&lt;br /&gt;
            current_number = current_number[:-1]&lt;br /&gt;
&lt;br /&gt;
            used_digits[digit] = False&lt;br /&gt;
&lt;br /&gt;
def calculate_sum_of_distinct_numbers(n):&lt;br /&gt;
    digits = [int(d) for d in str(n)]  &lt;br /&gt;
&lt;br /&gt;
    numbers = []  # List to store distinct numbers&lt;br /&gt;
    used_digits = {}  # Dictionary to track used digits&lt;br /&gt;
&lt;br /&gt;
    generate_numbers(n, digits, used_digits, &amp;quot;&amp;quot;, numbers)&lt;br /&gt;
&lt;br /&gt;
    numbers.sort()&lt;br /&gt;
&lt;br /&gt;
    sum_of_distinct_numbers = 0&lt;br /&gt;
    for i in range(len(numbers)):&lt;br /&gt;
        if i == 0 or numbers[i] != numbers[i - 1]:&lt;br /&gt;
            sum_of_distinct_numbers += numbers[i]&lt;br /&gt;
&lt;br /&gt;
    return sum_of_distinct_numbers&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    with open(&amp;quot;sumall.in&amp;quot;, &amp;quot;r&amp;quot;) as input_file:&lt;br /&gt;
        n = int(input_file.readline())&lt;br /&gt;
&lt;br /&gt;
    sum_of_distinct_numbers = calculate_sum_of_distinct_numbers(n)&lt;br /&gt;
&lt;br /&gt;
    with open(&amp;quot;sumall.out&amp;quot;, &amp;quot;w&amp;quot;) as output_file:&lt;br /&gt;
        output_file.write(str(sum_of_distinct_numbers))&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>Danciu</name></author>
	</entry>
</feed>