<?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=1398_-_Determinant</id>
	<title>1398 - Determinant - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=1398_-_Determinant"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1398_-_Determinant&amp;action=history"/>
	<updated>2026-05-01T04:04:23Z</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=1398_-_Determinant&amp;diff=7774&amp;oldid=prev</id>
		<title>Simina: Pagină nouă: = Cerința = Se dă o matrice pătratică de dimensiune &lt;code&gt;n&lt;/code&gt;. Să se calculeze determinantul ei.  = Date de intrare = Fișierul de intrare &lt;code&gt;determinantIN.txt&lt;/code&gt; conține pe prima linie numărul &lt;code&gt;n&lt;/code&gt;, iar pe următoarele &lt;code&gt;n&lt;/code&gt; linii câte &lt;code&gt;n&lt;/code&gt; numere întregi, reprezentând elementele matricei.  = Date de ieșire = Fișierul de ieșire &lt;code&gt;determinantOUT.txt&lt;/code&gt; va conține pe prima linie numărul &lt;code&gt;D&lt;/code&gt;, reprezentâ...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1398_-_Determinant&amp;diff=7774&amp;oldid=prev"/>
		<updated>2023-12-11T10:20:13Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: = Cerința = Se dă o matrice pătratică de dimensiune &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;. Să se calculeze determinantul ei.  = Date de intrare = Fișierul de intrare &amp;lt;code&amp;gt;determinantIN.txt&amp;lt;/code&amp;gt; conține pe prima linie numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, iar pe următoarele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; linii câte &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere întregi, reprezentând elementele matricei.  = Date de ieșire = Fișierul de ieșire &amp;lt;code&amp;gt;determinantOUT.txt&amp;lt;/code&amp;gt; va conține pe prima linie numărul &amp;lt;code&amp;gt;D&amp;lt;/code&amp;gt;, reprezentâ...&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ă o matrice pătratică de dimensiune &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;. Să se calculeze determinantul ei.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fișierul de intrare &amp;lt;code&amp;gt;determinantIN.txt&amp;lt;/code&amp;gt; conține pe prima linie numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, iar pe următoarele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; linii câte &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere întregi, reprezentând elementele matricei.&lt;br /&gt;
&lt;br /&gt;
= Date de ieșire =&lt;br /&gt;
Fișierul de ieșire &amp;lt;code&amp;gt;determinantOUT.txt&amp;lt;/code&amp;gt; va conține pe prima linie numărul &amp;lt;code&amp;gt;D&amp;lt;/code&amp;gt;, reprezentând valoarea determinantului.&lt;br /&gt;
&lt;br /&gt;
= Restricții și precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ n ≤ 10&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Exemplul 1 =&lt;br /&gt;
&amp;lt;code&amp;gt;determinantIN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 3&lt;br /&gt;
 1 -2 3&lt;br /&gt;
 0 1 -1&lt;br /&gt;
 2 1 -3&lt;br /&gt;
&amp;lt;code&amp;gt;determinantOUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 -4&lt;br /&gt;
&lt;br /&gt;
= Exemplul 2 =&lt;br /&gt;
&amp;lt;code&amp;gt;determinantIN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 20&lt;br /&gt;
 1 -2 3&lt;br /&gt;
 0 1 -1&lt;br /&gt;
 2 1 -3&lt;br /&gt;
&amp;lt;code&amp;gt;determinantOUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 Datele de intrare nu respectas restrictiile impuse.&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 are_restricții_valide(n, matrice):&lt;br /&gt;
    if not (1 &amp;lt;= n &amp;lt;= 10):&lt;br /&gt;
        return False&lt;br /&gt;
    &lt;br /&gt;
    for linie in matrice:&lt;br /&gt;
        if len(linie) != n:&lt;br /&gt;
            return False&lt;br /&gt;
    &lt;br /&gt;
    return True&lt;br /&gt;
&lt;br /&gt;
def calcul_cofactor(matrice, linie, coloana):&lt;br /&gt;
    submatrice = [row[:coloana] + row[coloana + 1:] for row in (matrice[:linie] + matrice[linie + 1:])]&lt;br /&gt;
    semn = (-1) ** (linie + coloana)&lt;br /&gt;
    return semn * calcul_determinant(submatrice)&lt;br /&gt;
&lt;br /&gt;
def calcul_determinant(matrice):&lt;br /&gt;
    n = len(matrice)&lt;br /&gt;
    if n == 1:&lt;br /&gt;
        return matrice[0][0]&lt;br /&gt;
    elif n == 2:&lt;br /&gt;
        return matrice[0][0] * matrice[1][1] - matrice[0][1] * matrice[1][0]&lt;br /&gt;
    else:&lt;br /&gt;
        determinant = 0&lt;br /&gt;
        for coloana in range(n):&lt;br /&gt;
            determinant += matrice[0][coloana] * calcul_cofactor(matrice, 0, coloana)&lt;br /&gt;
        return determinant&lt;br /&gt;
&lt;br /&gt;
# Citirea datelor de intrare&lt;br /&gt;
try:&lt;br /&gt;
    with open(&amp;quot;determinantIN.txt&amp;quot;, &amp;quot;r&amp;quot;) as file_in:&lt;br /&gt;
        n = int(file_in.readline().strip())&lt;br /&gt;
        matrice = [list(map(int, file_in.readline().split())) for _ in range(n)]&lt;br /&gt;
except FileNotFoundError:&lt;br /&gt;
    with open(&amp;quot;determinantOUT.txt&amp;quot;, &amp;quot;w&amp;quot;) as file_out:&lt;br /&gt;
        file_out.write(&amp;quot;Fișierul determinantIN.txt nu a fost găsit.&amp;quot;)&lt;br /&gt;
    exit()&lt;br /&gt;
except Exception as e:&lt;br /&gt;
    with open(&amp;quot;determinantOUT.txt&amp;quot;, &amp;quot;w&amp;quot;) as file_out:&lt;br /&gt;
        file_out.write(f&amp;quot;Eroare la citirea datelor de intrare: {str(e)}&amp;quot;)&lt;br /&gt;
    exit()&lt;br /&gt;
&lt;br /&gt;
# Verificarea restricțiilor&lt;br /&gt;
if not are_restricții_valide(n, matrice):&lt;br /&gt;
    with open(&amp;quot;determinantOUT.txt&amp;quot;, &amp;quot;w&amp;quot;) as file_out:&lt;br /&gt;
        file_out.write(&amp;quot;Datele de intrare nu respecta restrictiile impuse.&amp;quot;)&lt;br /&gt;
    exit()&lt;br /&gt;
&lt;br /&gt;
# Calculul determinantului&lt;br /&gt;
determinant = calcul_determinant(matrice)&lt;br /&gt;
&lt;br /&gt;
# Scrierea rezultatului în fișierul de ieșire&lt;br /&gt;
with open(&amp;quot;determinantOUT.txt&amp;quot;, &amp;quot;w&amp;quot;) as file_out:&lt;br /&gt;
    file_out.write(str(determinant))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Simina</name></author>
	</entry>
</feed>