<?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=Clasa_a_IX-a_lec%C8%9Bia_27</id>
	<title>Clasa a IX-a lecția 27 - 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=Clasa_a_IX-a_lec%C8%9Bia_27"/>
	<link rel="alternate" type="text/html" href="https://www.algopedia.ro/wiki/index.php?title=Clasa_a_IX-a_lec%C8%9Bia_27&amp;action=history"/>
	<updated>2026-04-15T08:26:06Z</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=Clasa_a_IX-a_lec%C8%9Bia_27&amp;diff=15073&amp;oldid=prev</id>
		<title>Bella: /* Tema Teorie */</title>
		<link rel="alternate" type="text/html" href="https://www.algopedia.ro/wiki/index.php?title=Clasa_a_IX-a_lec%C8%9Bia_27&amp;diff=15073&amp;oldid=prev"/>
		<updated>2018-04-22T07:43:06Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Tema Teorie&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Interclasarea a doi vectori (merge) ==&lt;br /&gt;
Se dau două şiruri a şi b, cu n, respectiv m elemente, numere naturale, ordonate crescător. Să se construiască un al treilea şir, c, care să conţină, în ordine crescătoare, elementele din şirurile a şi b.&lt;br /&gt;
&lt;br /&gt;
O soluție ar fi să copiem toate elementele în cel de-al treilea vector și apoi să îl ordonăm. Există însă o soluție mai bună, bazată pe faptul că vectorii sînt deja ordonați. Să observăm că primul element din vectorul final este minimul dintre primele elemente din vectorii inițiali. Îl putem deci copia și apoi îl eliminăm din vectorul din care face parte. Apoi reluăm procedura. La un moment dat unul din vectori se va goli. În acel moment copiem ceea ce a rămas din vectorul nevid. Vom folosi trei indici &amp;lt;tt&amp;gt;i1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;i2&amp;lt;/tt&amp;gt; și &amp;lt;tt&amp;gt;i3&amp;lt;/tt&amp;gt; care vor avansa în vectorii corespunzători, pe măsură ce selectăm elemente. Iată soluția:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int a[100000], b[100000], c[200000];&lt;br /&gt;
&lt;br /&gt;
int main(){&lt;br /&gt;
    int i, j, k, n1, n2;&lt;br /&gt;
    FILE *fin = fopen( &amp;quot;interclasare.in&amp;quot;, &amp;quot;r&amp;quot; );&lt;br /&gt;
    FILE *fout = fopen( &amp;quot;interclasare.out&amp;quot;, &amp;quot;w&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
    fscanf( fin, &amp;quot;%d&amp;quot;, &amp;amp;n1 );&lt;br /&gt;
    for( i = 0; i &amp;lt; n1; i++ )&lt;br /&gt;
        fscanf(fin, &amp;quot;%d&amp;quot;, &amp;amp;a[i]);&lt;br /&gt;
    &lt;br /&gt;
    fscanf(fin, &amp;quot;%d&amp;quot;, &amp;amp;n2);&lt;br /&gt;
    for( i = 0; i &amp;lt; n2; i++ )&lt;br /&gt;
        fscanf(fin, &amp;quot;%d&amp;quot;, &amp;amp;b[i]);&lt;br /&gt;
&lt;br /&gt;
    i = j = k = 0;&lt;br /&gt;
    while( i &amp;lt; n1 &amp;amp;&amp;amp; j &amp;lt; n2 ){      // cate vreme mai avem elemente in ambii vectori&lt;br /&gt;
        if( a[i] &amp;lt; b[j] )           // daca in a avem elementul mai mic&lt;br /&gt;
            c[k++] = a[i++];        // il copiem in vectorul c; avansam in vectorul a si in vectorul c&lt;br /&gt;
        else                        // altfel b are elementul cel mai mic&lt;br /&gt;
            c[k++] = b[j++];        // il copiem in vectorul c; avansam in vectorul b si in vectorul c&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
    // in acest moment unul din vectorii a, b este sigur vid,&lt;br /&gt;
    while ( i &amp;lt; n1 )                // incercam sa copiem elementele ramase in a, daca exista&lt;br /&gt;
        c[k++] = a[i++];&lt;br /&gt;
&lt;br /&gt;
    while ( j &amp;lt; n2 )                // incercam sa copiem elementele ramase in b, daca exista&lt;br /&gt;
        c[k++] = b[j++];&lt;br /&gt;
&lt;br /&gt;
    for( i = 0; i &amp;lt; k; i++ ){       // k va fi n1 + n2&lt;br /&gt;
        fprintf ( fout, &amp;quot;%d &amp;quot;,  c[i] );        &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;br /&gt;
&lt;br /&gt;
= Laborator = &lt;br /&gt;
=== #251 Interclasare2 ===	&lt;br /&gt;
Se dau două şiruri a şi b, cu n, respectiv m elemente, numere naturale, ordonate strict crescător. Să se afişeze, în ordine strict crescătoare, valorile existente în ambele şiruri.&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== #284 Interclasare3	===&lt;br /&gt;
Se dau două şiruri, cu n, respectiv m, elemente, numere naturale. Primul şir este ordonat crescător, iar al doilea element este ordonat descrescător. Să se afişeze, în ordine crescătoare, valorile pare din cele două şiruri.&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
===#530 Multimi1===	&lt;br /&gt;
Se dau două mulțimi de numere naturale. Să se afișeze reuniunea și intersecția lor. &lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
=== #242 InterclasM ===&lt;br /&gt;
Se dă un număr natural x și două șiruri a și b, cu n, respectiv m elemente, numere naturale, ordonate strict crescător. Să se afișeze, în ordine crescătoare, multiplii lui x care se află doar în unul dintre cele două șiruri.&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Tema Teorie =&lt;br /&gt;
Interclasare1,  Interclasare&lt;br /&gt;
&lt;br /&gt;
===#241 Interclasare===	&lt;br /&gt;
Se dau două şiruri a şi b, cu n, respectiv m elemente, numere naturale, ordonate crescător. Să se construiască un al treilea şir, c, care să conţină, în ordine crescătoare, elementele din şirurile a şi b.&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int a[100000], b[100000], c[200000];&lt;br /&gt;
&lt;br /&gt;
int main(){&lt;br /&gt;
    int i, j, k, n1, n2, n;&lt;br /&gt;
    FILE *fin = fopen( &amp;quot;interclasare.in&amp;quot;, &amp;quot;r&amp;quot; );&lt;br /&gt;
    FILE *fout = fopen( &amp;quot;interclasare.out&amp;quot;, &amp;quot;w&amp;quot; );&lt;br /&gt;
    fscanf( fin, &amp;quot;%d&amp;quot;, &amp;amp;n1 );&lt;br /&gt;
    for( i = 0; i &amp;lt; n1; i++ )&lt;br /&gt;
        fscanf(fin, &amp;quot;%d&amp;quot;, &amp;amp;a[i]);&lt;br /&gt;
    fscanf(fin, &amp;quot;%d&amp;quot;, &amp;amp;n2);&lt;br /&gt;
    for( i = 0; i &amp;lt; n2; i++ )&lt;br /&gt;
        fscanf(fin, &amp;quot;%d&amp;quot;, &amp;amp;b[i]);&lt;br /&gt;
&lt;br /&gt;
    i = j = k = 0;&lt;br /&gt;
    while( i &amp;lt; n1 &amp;amp;&amp;amp; j &amp;lt; n2 ){      /// cate vreme mai avem elemente in ambii vectori&lt;br /&gt;
        if( a[i] &amp;lt; b[j] )           /// daca in a avem elementul mai mic&lt;br /&gt;
            c[k++] = a[i++];        /// il copiem in vectorul c; avansam in vectorul a si in vectorul c&lt;br /&gt;
        else                        /// altfel b are elementul cel mai mic&lt;br /&gt;
            c[k++] = b[j++];        /// il copiem in vectorul c; avansam in vectorul b si in vectorul c&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
    /// in acest moment unul din vectorii a, b este sigur vid,&lt;br /&gt;
    while ( i &amp;lt; n1 )                /// incercam sa copiem elementele ramase in a, daca exista&lt;br /&gt;
        c[k++] = a[i++];&lt;br /&gt;
&lt;br /&gt;
    while ( j &amp;lt; n2 )                /// incercam sa copiem elementele ramase in b, daca exista&lt;br /&gt;
        c[k++] = b[j++];&lt;br /&gt;
&lt;br /&gt;
    n = n1 + n2;&lt;br /&gt;
    for( i = 0; i &amp;lt; n; i++ ){&lt;br /&gt;
        fprintf ( fout, &amp;quot;%d &amp;quot;,  c[i] );&lt;br /&gt;
        if( ( i + 1 ) % 10 == 0 )  /// dupa ce am printat al 10-lea element dau enter&lt;br /&gt;
            fprintf ( fout, &amp;quot;\n&amp;quot; );&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== #250 Interclasare1 ===	&lt;br /&gt;
Se dau două şiruri a şi b, cu n, respectiv m elemente, numere naturale, ordonate strict crescător. Să se afişeze, în ordine strict crescătoare, valorile existente în cel puţin unul dintre cele două şiruri.&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int a[100000], b[100000], c[200000];&lt;br /&gt;
&lt;br /&gt;
int main(){&lt;br /&gt;
  int i, j, k, n1, n2, n;&lt;br /&gt;
  FILE *fin = fopen( &amp;quot;interclasare1.in&amp;quot;, &amp;quot;r&amp;quot; );&lt;br /&gt;
  FILE *fout = fopen( &amp;quot;interclasare1.out&amp;quot;, &amp;quot;w&amp;quot; );&lt;br /&gt;
  &lt;br /&gt;
  fscanf( fin, &amp;quot;%d&amp;quot;, &amp;amp;n1 );&lt;br /&gt;
  for( i = 0; i &amp;lt; n1; i++ )&lt;br /&gt;
    fscanf(fin, &amp;quot;%d&amp;quot;, &amp;amp;a[i]);&lt;br /&gt;
  &lt;br /&gt;
  fscanf(fin, &amp;quot;%d&amp;quot;, &amp;amp;n2);&lt;br /&gt;
  for( i = 0; i &amp;lt; n2; i++ )&lt;br /&gt;
    fscanf(fin, &amp;quot;%d&amp;quot;, &amp;amp;b[i]);&lt;br /&gt;
&lt;br /&gt;
  i = j = k = 0;&lt;br /&gt;
  while( i &amp;lt; n1 &amp;amp;&amp;amp; j &amp;lt; n2 ){      /// cate vreme mai avem elemente in ambii vectori&lt;br /&gt;
    if( a[i] &amp;lt; b[j] ) {&lt;br /&gt;
      if ( a[i] != c[k-1] )&lt;br /&gt;
        c[k++] = a[i];&lt;br /&gt;
      i++;&lt;br /&gt;
    }        /// il copiem in vectorul c; avansam in vectorul a si in vectorul c&lt;br /&gt;
    else {&lt;br /&gt;
      if ( b[j] != c[k-1] )&lt;br /&gt;
        c[k++] = b[j];&lt;br /&gt;
      j++;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  while ( i &amp;lt; n1 ){&lt;br /&gt;
    if ( a[i] != c[k-1] )&lt;br /&gt;
      c[k++] = a[i];&lt;br /&gt;
    i++;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  while ( j &amp;lt; n2 ){&lt;br /&gt;
    if ( b[j] != c[k-1] )&lt;br /&gt;
      c[k++] = b[j];&lt;br /&gt;
    j++;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  for( i = 0; i &amp;lt; k; i++ ){&lt;br /&gt;
    fprintf ( fout, &amp;quot;%d &amp;quot;,  c[i] );&lt;br /&gt;
    if( ( i + 1 ) % 10 == 0 )   /// dupa ce am printat al 10-lea element dau enter&lt;br /&gt;
      fprintf ( fout, &amp;quot;\n&amp;quot; );&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Tema Laborator =&lt;br /&gt;
Interclasare2, Interclasare3, Multimi1, InterclasM&lt;/div&gt;</summary>
		<author><name>Bella</name></author>
	</entry>
</feed>