<?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=3025_-_PCR</id>
	<title>3025 - PCR - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=3025_-_PCR"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=3025_-_PCR&amp;action=history"/>
	<updated>2026-05-01T05:37:57Z</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=3025_-_PCR&amp;diff=10106&amp;oldid=prev</id>
		<title>Danciu: Pagină nouă:  = Cerința = Se dă &lt;code&gt;n&lt;/code&gt; un număr natural. Cifrele lui &lt;code&gt;n&lt;/code&gt; se permută pentru a forma un număr natural, de aceeași lungime cu &lt;code&gt;n&lt;/code&gt;, și care să fie palindrom. Aflați câte asemenea numere se pot obține.  = Date de intrare = Programul citește de la tastatură numărul &lt;code&gt;n&lt;/code&gt;.  = Date de ieșire = Programul va afișa pe ecran numărul de palindromuri care se pot obține prin permutarea cifrelor lui &lt;code&gt;n&lt;/code&gt;.  = Restricții ș...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=3025_-_PCR&amp;diff=10106&amp;oldid=prev"/>
		<updated>2024-06-04T08:32:34Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă:  = Cerința = Se dă &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; un număr natural. Cifrele lui &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; se permută pentru a forma un număr natural, de aceeași lungime cu &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, și care să fie palindrom. Aflați câte asemenea numere se pot obține.  = Date de intrare = Programul citește de la tastatură numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;.  = Date de ieșire = Programul va afișa pe ecran numărul de palindromuri care se pot obține prin permutarea cifrelor lui &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;.  = Restricții ș...&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;
Se dă &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; un număr natural. Cifrele lui &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; se permută pentru a forma un număr natural, de aceeași lungime cu &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, și care să fie palindrom. Aflați câte asemenea numere se pot obține.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Programul citește de la tastatură 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;
Programul va afișa pe ecran numărul de palindromuri care se pot obține prin permutarea cifrelor lui &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 ≤ n ≤ 1038&amp;lt;/code&amp;gt;&lt;br /&gt;
* PCR este prescurtarea de la [[Index.php/Clasele 9-10 lecția 25 - 1 apr 2015|Permutări Cu Repetiţie]]&lt;br /&gt;
&lt;br /&gt;
= Exemplu: =&lt;br /&gt;
Intrare&lt;br /&gt;
 1102022&lt;br /&gt;
Ieșire&lt;br /&gt;
 4&lt;br /&gt;
&lt;br /&gt;
=== Explicație ===&lt;br /&gt;
Permutând cifrele lui &amp;lt;code&amp;gt;1102022&amp;lt;/code&amp;gt; se pot obține următoarele palindromuri de aceeași lungime cu &amp;lt;code&amp;gt;1102022&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;1022201&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;1202021&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;2012102&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;2102012&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 count_palindrome_permutations(n):&lt;br /&gt;
    total_palindromes = 0&lt;br /&gt;
    num_even_digits = 0&lt;br /&gt;
    num_odd_digits = 0&lt;br /&gt;
    duplicated_digit_count = 0&lt;br /&gt;
&lt;br /&gt;
    while n &amp;gt; 0:&lt;br /&gt;
        digit = n % 10&lt;br /&gt;
        if digit % 2 == 0:&lt;br /&gt;
            num_even_digits += 1&lt;br /&gt;
        else:&lt;br /&gt;
            num_odd_digits += 1&lt;br /&gt;
        n //= 10&lt;br /&gt;
&lt;br /&gt;
    if num_even_digits &amp;gt; 1 or num_odd_digits &amp;gt; 1:&lt;br /&gt;
        duplicated_digit_count = 1&lt;br /&gt;
&lt;br /&gt;
    if num_even_digits % 2 == 0:&lt;br /&gt;
        total_palindromes += (num_even_digits // 2)! * (num_odd_digits // 2)!&lt;br /&gt;
&lt;br /&gt;
    if num_odd_digits % 2 == 0:&lt;br /&gt;
        total_palindromes += (num_odd_digits // 2)! * (num_even_digits // 2)!&lt;br /&gt;
&lt;br /&gt;
    if num_odd_digits == 1 and num_even_digits &amp;gt; 0:&lt;br /&gt;
        total_palindromes += (num_even_digits // 2)! * duplicated_digit_count&lt;br /&gt;
&lt;br /&gt;
    if num_even_digits == 1 and num_odd_digits &amp;gt; 0:&lt;br /&gt;
        total_palindromes += (num_odd_digits // 2)! * duplicated_digit_count&lt;br /&gt;
&lt;br /&gt;
    return total_palindromes&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    n = int(input())&lt;br /&gt;
    palindrome_count = count_palindrome_permutations(n)&lt;br /&gt;
    print(palindrome_count)&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>