<?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=0194_-_Anagrame1</id>
	<title>0194 - Anagrame1 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=0194_-_Anagrame1"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0194_-_Anagrame1&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=0194_-_Anagrame1&amp;diff=7606&amp;oldid=prev</id>
		<title>Gabii: Pagină nouă:  == Enunț == Se numește &#039;&#039;anagramă&#039;&#039; a unui cuvânt dat, un alt cuvânt ce conține toate literele primului, eventual în altă ordine.  = Cerinţa = Se dă un cuvânt din cel mult &lt;code&gt;8&lt;/code&gt; litere distincte. Să se afișeze, în ordine alfabetică, toate anagramele acestui cuvânt.  = Date de intrare = Fişierul de intrare &lt;code&gt;anagrameIN.txt&lt;/code&gt; conţine pe pe prima linie un cuvânt &lt;code&gt;S&lt;/code&gt;, format din cel mult &lt;code&gt;8&lt;/code&gt; litere distincte ale alfabetu...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0194_-_Anagrame1&amp;diff=7606&amp;oldid=prev"/>
		<updated>2023-12-04T12:13:04Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă:  == Enunț == Se numește &amp;#039;&amp;#039;anagramă&amp;#039;&amp;#039; a unui cuvânt dat, un alt cuvânt ce conține toate literele primului, eventual în altă ordine.  = Cerinţa = Se dă un cuvânt din cel mult &amp;lt;code&amp;gt;8&amp;lt;/code&amp;gt; litere distincte. Să se afișeze, în ordine alfabetică, toate anagramele acestui cuvânt.  = Date de intrare = Fişierul de intrare &amp;lt;code&amp;gt;anagrameIN.txt&amp;lt;/code&amp;gt; conţine pe pe prima linie un cuvânt &amp;lt;code&amp;gt;S&amp;lt;/code&amp;gt;, format din cel mult &amp;lt;code&amp;gt;8&amp;lt;/code&amp;gt; litere distincte ale alfabetu...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
== Enunț ==&lt;br /&gt;
Se numește &amp;#039;&amp;#039;anagramă&amp;#039;&amp;#039; a unui cuvânt dat, un alt cuvânt ce conține toate literele primului, eventual în altă ordine.&lt;br /&gt;
&lt;br /&gt;
= Cerinţa =&lt;br /&gt;
Se dă un cuvânt din cel mult &amp;lt;code&amp;gt;8&amp;lt;/code&amp;gt; litere distincte. Să se afișeze, în ordine alfabetică, toate anagramele acestui cuvânt.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fişierul de intrare &amp;lt;code&amp;gt;anagrameIN.txt&amp;lt;/code&amp;gt; conţine pe pe prima linie un cuvânt &amp;lt;code&amp;gt;S&amp;lt;/code&amp;gt;, format din cel mult &amp;lt;code&amp;gt;8&amp;lt;/code&amp;gt; litere distincte ale alfabetului englez.&lt;br /&gt;
&lt;br /&gt;
= Date de ieşire =&lt;br /&gt;
Fişierul de ieşire &amp;lt;code&amp;gt;anagrameOUT.txt&amp;lt;/code&amp;gt; va conţine toate anagramele cuvântului &amp;lt;code&amp;gt;S&amp;lt;/code&amp;gt;, fiecare pe o linie, în ordine alfabetică.&lt;br /&gt;
&lt;br /&gt;
= Exemplul 1 =&lt;br /&gt;
&amp;lt;code&amp;gt;anagrameIN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
cal&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;anagrameOUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 acl&lt;br /&gt;
 alc&lt;br /&gt;
 cal&lt;br /&gt;
 cla&lt;br /&gt;
 lac&lt;br /&gt;
 lca&lt;br /&gt;
&lt;br /&gt;
== Exemplul 2 ==&lt;br /&gt;
&amp;lt;code&amp;gt;anagrameIN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 4tal&lt;br /&gt;
consola&lt;br /&gt;
 Cuvântul trebuie să aibă între 1 și 8 litere și să nu conțină numere.&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;
from itertools import permutations&lt;br /&gt;
&lt;br /&gt;
def generate_anagrams(word):&lt;br /&gt;
    # Generăm toate permutările cuvântului&lt;br /&gt;
    all_permutations = permutations(word)&lt;br /&gt;
&lt;br /&gt;
    # Sortăm permutările în ordine alfabetică&lt;br /&gt;
    sorted_anagrams = sorted(set(&amp;#039;&amp;#039;.join(perm) for perm in all_permutations))&lt;br /&gt;
&lt;br /&gt;
    return sorted_anagrams&lt;br /&gt;
&lt;br /&gt;
def validate_word(word):&lt;br /&gt;
    # Verificăm restricțiile&lt;br /&gt;
    return 1 &amp;lt;= len(word) &amp;lt;= 8 and word.isalpha()&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    try:&lt;br /&gt;
        # Citim cuvântul din fișierul de intrare&lt;br /&gt;
        with open(&amp;quot;anagrameIN.txt&amp;quot;, &amp;quot;r&amp;quot;) as file:&lt;br /&gt;
            word = file.readline().strip()&lt;br /&gt;
&lt;br /&gt;
        # Verificăm restricțiile utilizând funcția separată&lt;br /&gt;
        if not validate_word(word):&lt;br /&gt;
            print(&amp;quot;Cuvântul trebuie să aibă între 1 și 8 litere și să nu conțină numere.&amp;quot;)&lt;br /&gt;
            return&lt;br /&gt;
&lt;br /&gt;
        # Generăm anagramele&lt;br /&gt;
        anagrams = generate_anagrams(word)&lt;br /&gt;
&lt;br /&gt;
        # Scriem anagramele în fișierul de ieșire&lt;br /&gt;
        with open(&amp;quot;anagrameOUT.txt&amp;quot;, &amp;quot;w&amp;quot;) as file:&lt;br /&gt;
            for anagram in anagrams:&lt;br /&gt;
                file.write(anagram + &amp;#039;\n&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
    except Exception as e:&lt;br /&gt;
        print(f&amp;quot;A intervenit o eroare: {e}&amp;quot;)&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>