<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.algopedia.ro/wiki/index.php?action=history&amp;feed=atom&amp;title=9</id>
	<title>9 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.algopedia.ro/wiki/index.php?action=history&amp;feed=atom&amp;title=9"/>
	<link rel="alternate" type="text/html" href="https://www.algopedia.ro/wiki/index.php?title=9&amp;action=history"/>
	<updated>2026-04-17T08:24:36Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://www.algopedia.ro/wiki/index.php?title=9&amp;diff=13380&amp;oldid=prev</id>
		<title>Bella: /* Subiectul III */</title>
		<link rel="alternate" type="text/html" href="https://www.algopedia.ro/wiki/index.php?title=9&amp;diff=13380&amp;oldid=prev"/>
		<updated>2016-05-25T13:44:32Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Subiectul III&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Teza =&lt;br /&gt;
== Nr.1 ==&lt;br /&gt;
===Subiectul I ===&lt;br /&gt;
Din fișierul pr1nr1.in se citesc n numere naturale cu cel mult 4 cifre (0 &amp;lt; n &amp;lt; 1.000.000). &lt;br /&gt;
* a. Să se afișeze pe prima linie a fisierului pr1nr1.out, în ordine crescătoare, toate numerele cu exact 3 cifre care apar în fișierul inițial.&lt;br /&gt;
* b. Să se afișeze pe linia a doua, în fișierul pr1nr1.out, numărul care apare de cele mai multe ori. Dacă sunt mai multe numere să se afișeze cel mai mare dintre acestea.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Rezolvare:&amp;#039;&amp;#039;&amp;#039; Vom construi un vector de frecventa, unde v[i] va fi nr de aparitii ale lui i in sirul dat. Cum valorile din sir pot avea maxim 4 cifre, ultima casuta din acesta va fi 9999.&lt;br /&gt;
Deci vom declara un vector de dimensiune 10000.&lt;br /&gt;
Pentru rezolvarea punctului a, vom parcurge vectorul de frecventa de la pozitia 100 pana la 999 ( toate numerele de 3 cifre ) si le vom afisa numai daca v[i] e nenul ( i este insirul initial ).&lt;br /&gt;
Pentru punctul b, vom afisa valoarea maxima din intregul vector de frecventa ( de la 0 la 9999)&lt;br /&gt;
Iata implementarea acestei solutii:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
int v[10000];&lt;br /&gt;
int main(){&lt;br /&gt;
  int n, fmax, vmax, i, x;&lt;br /&gt;
  FILE *fin, *fout;&lt;br /&gt;
  fin = fopen( &amp;quot;pr1nr1.in&amp;quot;, &amp;quot;r&amp;quot; );&lt;br /&gt;
  fout = fopen( &amp;quot;pr1nr1.out&amp;quot;, &amp;quot;w&amp;quot; );&lt;br /&gt;
  //citim cele n valori si construim vectorul de frecventa&lt;br /&gt;
  fscanf( fin, &amp;quot;%d&amp;quot;, &amp;amp;n );&lt;br /&gt;
  for( i = 0; i &amp;lt; n; i++ ){&lt;br /&gt;
    fscanf(fin, &amp;quot;%d&amp;quot;, &amp;amp;x);&lt;br /&gt;
    v[x]++;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  //a) afisam in ordine numerele de 3 cifre care apar in sir&lt;br /&gt;
  for( i = 100; i &amp;lt;= 999; i++ ){&lt;br /&gt;
    x = v[i];&lt;br /&gt;
    while( x-- )&lt;br /&gt;
      fprintf(fout, &amp;quot;%d &amp;quot;, i);&lt;br /&gt;
  }&lt;br /&gt;
  fprintf( fout, &amp;quot;\n&amp;quot; );&lt;br /&gt;
  //b) determinam valoarea maxima a frecventelor de aparitie si retinem valoare care are frecventa maxima&lt;br /&gt;
  fmax = v[0]; vmax = 0;&lt;br /&gt;
  for( i = 1; i &amp;lt;= 9999; i++ )&lt;br /&gt;
    if( v[i] &amp;gt;= fmax ){&lt;br /&gt;
      fmax = v[i];&lt;br /&gt;
      vmax = i;&lt;br /&gt;
    }&lt;br /&gt;
  fprintf( fout, &amp;quot;%d\n&amp;quot;, vmax );&lt;br /&gt;
  fclose( fin );&lt;br /&gt;
  fclose( fout );&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Subiectul II ===&lt;br /&gt;
Din fișierul pr2nr1.in se citesc n ( 0 &amp;lt; n &amp;lt;  100 ),  numere naturale cu cel mult 14 cifre. &lt;br /&gt;
* a. Să se sorteze crescator numerele si sa se afișeze pe prima linie a fișierulul pr2nr1.out numerele din sir in ordine crescatoare din prima jumatate a vectorului sortat, exclusiv elementul din mijloc, in caz ca sirul are numar impar de valori.&lt;br /&gt;
* b. Pe a doua  linie a aceluiasi fisier afisati  cel mai mare divizor comun dintre suma elementelor din prima jumatate si a doua jumatate a vectorului sortat. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Rezolvare:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
long long v[100], aux, s1, s2, r;&lt;br /&gt;
&lt;br /&gt;
int main(){&lt;br /&gt;
  FILE *fin, *fout;&lt;br /&gt;
  fin = fopen( &amp;quot;pr2nr1.in&amp;quot;, &amp;quot;r&amp;quot; );&lt;br /&gt;
  fout = fopen( &amp;quot;pr2nr1.out&amp;quot;, &amp;quot;w&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
  int n, i, j;&lt;br /&gt;
&lt;br /&gt;
  // citim elementele sirului si le vom pune intr-un vector v&lt;br /&gt;
  fscanf( fin, &amp;quot;%d&amp;quot;, &amp;amp;n );&lt;br /&gt;
  for ( i = 0; i &amp;lt; n; i++ )&lt;br /&gt;
    fscanf( fin, &amp;quot;%lld&amp;quot;, &amp;amp;v[i] );&lt;br /&gt;
&lt;br /&gt;
  // sortam elementele vectorului v&lt;br /&gt;
  for ( i = 0; i &amp;lt; n-1; i++ )&lt;br /&gt;
    for ( j = i+1; j &amp;lt; n; j++ )&lt;br /&gt;
      if ( v[i] &amp;gt; v[j] ){&lt;br /&gt;
        aux = v[i];&lt;br /&gt;
        v[i] = v[j];&lt;br /&gt;
        v[j] = aux;&lt;br /&gt;
    }&lt;br /&gt;
  //afisam prima jumatate a vect sortat&lt;br /&gt;
  for ( i = 0; i &amp;lt; n/2; i++ )&lt;br /&gt;
    fprintf( fout, &amp;quot;%lld &amp;quot;, v[i] );&lt;br /&gt;
  fprintf( fout, &amp;quot;\n&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
  //calculam simultan cele doua sume&lt;br /&gt;
  s1 = s2 = 0;&lt;br /&gt;
  for ( i = 0; i &amp;lt; n / 2; i++ ){&lt;br /&gt;
    s1 += v[i];&lt;br /&gt;
    s2 += v[n-i-1];&lt;br /&gt;
  }&lt;br /&gt;
  //cmmdc intre s1 si s2&lt;br /&gt;
  while ( s2 ){&lt;br /&gt;
    r = s1 % s2;&lt;br /&gt;
    s1 = s2;&lt;br /&gt;
    s2 = r;&lt;br /&gt;
  }&lt;br /&gt;
  fprintf( fout, &amp;quot;%lld\n&amp;quot;, s1 );&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Subiectul III===&lt;br /&gt;
Din fișierul pr3nr1.in se citesc, de pe prima linie 3 numere naturale nenule n, m, x,  1 &amp;lt; n, m &amp;lt; 100, iar de pe urmatoarele m linii se citesc câte n numere naturale cu cel mult 8 cifre, reprezentand elementele unei matrici. &lt;br /&gt;
a. Afisati pe prima linie a fisierului  pr3nr1.out  linia si coloana primei aparitii a lui x in matrice.    &lt;br /&gt;
b. Afisati pe a doua linie a fisierului  pr3nr1.out  numarul de aparitii ale lui x in matrice.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Rezolvare:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(){&lt;br /&gt;
  int i, j, l, c, x, co, nr, ok;&lt;br /&gt;
  FILE *fin, *fout;&lt;br /&gt;
  fin = fopen( &amp;quot;pr3nr1.in&amp;quot;, &amp;quot;r&amp;quot; );&lt;br /&gt;
  fout = fopen( &amp;quot;pr3nr1.out&amp;quot;, &amp;quot;w&amp;quot; );&lt;br /&gt;
  fscanf( fin, &amp;quot;%d%d%d&amp;quot;, &amp;amp;l, &amp;amp;c, &amp;amp;x );&lt;br /&gt;
  contor = 0;  //nr de aparitii&lt;br /&gt;
  for( i=1; i&amp;lt;=l; i++ )            //parcurgem intreaga matrice&lt;br /&gt;
    for( j=1; j&amp;lt;=c; j++ ){&lt;br /&gt;
      fscanf( fin, &amp;quot;%d&amp;quot;, &amp;amp;nr );&lt;br /&gt;
      if( nr == x ){                //numaram de cate ori apare x in matrice&lt;br /&gt;
        contor++; &lt;br /&gt;
        if( contor == 1 )            //daca suntem la prima aparitie           &lt;br /&gt;
          fprintf( fout, &amp;quot;%d %d\n&amp;quot;, i, j ); //afisam coordonatele aparitiei respective &lt;br /&gt;
      }  &lt;br /&gt;
   }&lt;br /&gt;
    &lt;br /&gt;
  fprintf( fout, &amp;quot;%d\n&amp;quot;, contor );&lt;br /&gt;
  fclose( fin );&lt;br /&gt;
  fclose( fout );&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Subiectul IV ===&lt;br /&gt;
Din fișierul pr4nr1.in se citesc, de pe prima linie un numar natural nenul n, 1&amp;lt;n&amp;lt;100. De pe urmatoarele n linii se citesc câte n numere naturale cu cel mult 8 cifre, reprezentant elementele unei matrice patratice. &lt;br /&gt;
* a. Să se afiseze in pr4nr1.out pe prima linie suma elementelor de pe toate liniile care au ca prim element un numar prim .&lt;br /&gt;
* b. Să se afiseze in pr4nr1.out pe a doua linie cate numere care au exact 3 cifre sunt in triunghiul de sub  diagonala principala.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Rezolvare:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
long long suma;&lt;br /&gt;
int m[100][100];&lt;br /&gt;
int main(){&lt;br /&gt;
  int n, e, d, ok, i, j;&lt;br /&gt;
  FILE *fin, *fout;&lt;br /&gt;
  fin=fopen(&amp;quot;pr4nr1.in&amp;quot;, &amp;quot;r&amp;quot;);&lt;br /&gt;
  fout=fopen(&amp;quot;pr4nr1.out&amp;quot;, &amp;quot;w&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
  //citirea matricei&lt;br /&gt;
  fscanf(fin, &amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
  for( i = 0; i &amp;lt; n; i++ )&lt;br /&gt;
    for(j = 0; j &amp;lt; n; j++ )&lt;br /&gt;
      fscanf( fin, &amp;quot;%d&amp;quot;, &amp;amp;m[i][j] );&lt;br /&gt;
&lt;br /&gt;
  for( i = 0; i &amp;lt; n; i++){&lt;br /&gt;
    //verific ca primul elem de pe linia i, m[i][0],  e prim&lt;br /&gt;
    d = 2;&lt;br /&gt;
    while(d * d &amp;lt;= m[i][0] &amp;amp;&amp;amp; m[i][0] % d )&lt;br /&gt;
      d++;&lt;br /&gt;
&lt;br /&gt;
    //daca e prim adaugam toate elementele de pe linia i la suma&lt;br /&gt;
    if( d * d &amp;gt; m[i][0] &amp;amp;&amp;amp; m[i][0] &amp;gt; 1 )&lt;br /&gt;
      for( j = 0; j &amp;lt; n; j++ )&lt;br /&gt;
        suma += m[i][j];&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  fprintf(fout, &amp;quot;%lld\n&amp;quot;, suma);&lt;br /&gt;
&lt;br /&gt;
  //parcurgerea triunghiului de sub diagonala principala&lt;br /&gt;
  suma = 0;&lt;br /&gt;
  for (i = 0; i &amp;lt; n; i++ )&lt;br /&gt;
    for (j = 0; j &amp;lt; i; j++ ){&lt;br /&gt;
      if ( m[i][j] &amp;gt;= 100 &amp;amp;&amp;amp; m[i][j] &amp;lt;= 999 )&lt;br /&gt;
        suma++;&lt;br /&gt;
    }&lt;br /&gt;
  fprintf( fout, &amp;quot;%d\n&amp;quot;, suma );&lt;br /&gt;
&lt;br /&gt;
  fclose( fin );&lt;br /&gt;
  fclose( fout );&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bella</name></author>
	</entry>
</feed>