<?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_V-a_lec%C8%9Bia_6_S7</id>
	<title>Clasa a V-a lecția 6 S7 - 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_V-a_lec%C8%9Bia_6_S7"/>
	<link rel="alternate" type="text/html" href="https://www.algopedia.ro/wiki/index.php?title=Clasa_a_V-a_lec%C8%9Bia_6_S7&amp;action=history"/>
	<updated>2026-04-13T14:00:23Z</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_V-a_lec%C8%9Bia_6_S7&amp;diff=14092&amp;oldid=prev</id>
		<title>Bella: Created page with &quot;= Tema6 Rezolvari=  * (usoara) &#039;&#039;&#039;2 la n &#039;&#039;&#039;:Sa se calculeze 2 la puterea n. * (usoara) &#039;&#039;&#039;Eliminarea primei cifre&#039;&#039;&#039;: Se citeste un numar n. Afisati numarul rezultat prin eli...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.algopedia.ro/wiki/index.php?title=Clasa_a_V-a_lec%C8%9Bia_6_S7&amp;diff=14092&amp;oldid=prev"/>
		<updated>2017-11-04T20:34:36Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Tema6 Rezolvari=  * (usoara) &amp;#039;&amp;#039;&amp;#039;2 la n &amp;#039;&amp;#039;&amp;#039;:Sa se calculeze 2 la puterea n. * (usoara) &amp;#039;&amp;#039;&amp;#039;Eliminarea primei cifre&amp;#039;&amp;#039;&amp;#039;: Se citeste un numar n. Afisati numarul rezultat prin eli...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Tema6 Rezolvari= &lt;br /&gt;
* (usoara) &amp;#039;&amp;#039;&amp;#039;2 la n &amp;#039;&amp;#039;&amp;#039;:Sa se calculeze 2 la puterea n.&lt;br /&gt;
* (usoara) &amp;#039;&amp;#039;&amp;#039;Eliminarea primei cifre&amp;#039;&amp;#039;&amp;#039;: Se citeste un numar n. Afisati numarul rezultat prin eliminarea primei cifre a lui n.&lt;br /&gt;
* (medie)  &amp;#039;&amp;#039;&amp;#039;Extragere cifre pare&amp;#039;&amp;#039;&amp;#039; : Se citeste un numar n, de maxim 9 cifre dintr-un fisier &amp;quot;date.in&amp;quot;. Afisati numarul care contine, in aceeasi ordine doar cifrele pare ale lui n, intr-un fisier &amp;quot;date.out&amp;quot;. Ex: n= 12345, Se va afisa 24;&lt;br /&gt;
* (medie)  &amp;#039;&amp;#039;&amp;#039;Cifra de control&amp;#039;&amp;#039;&amp;#039;: Se citeste un numar n. Afisati cifra de control a numarul n. Cifra de control se obtine prin adunarea repetata a cifrelor numarului pana cand se obtine o singura cifra. Ex: n=193, s=1+9+3=13, s=1+3=4&lt;br /&gt;
* (dificila - optional) &amp;#039;&amp;#039;&amp;#039;Numere palindrom apropiate de n&amp;#039;&amp;#039;&amp;#039;: Se citeste un numar n. Sa se afiseze cel mai apropiat fata de n numar palindrom.&lt;br /&gt;
Ex1: 122 , afisam 121; nr 122 e cuprins intre 121 si 131, iar 121 este mai apropiat fata de 122.&lt;br /&gt;
Ex2: 452 , afisam 454; nr 452 este cuprins intre 444 si 454.&lt;br /&gt;
&lt;br /&gt;
=== 2 la n ===&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 main() {&lt;br /&gt;
  int n, contor;&lt;br /&gt;
&lt;br /&gt;
  scanf( &amp;quot;%d&amp;quot;, &amp;amp;n );&lt;br /&gt;
  contor = 0; &lt;br /&gt;
  p = 1;&lt;br /&gt;
  while (  contor &amp;lt; n ) {&lt;br /&gt;
    p = p * 2;&lt;br /&gt;
    contor= contor + 1;&lt;br /&gt;
  }&lt;br /&gt;
  printf( &amp;quot;%d &amp;quot;, p );&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Extragere cifre pare din n===&lt;br /&gt;
* 2. Se citeste un numar n, de maxim 9 cifre dintr-un fisier &amp;quot;date.in&amp;quot;. Afisati numarul care contine, in aceeasi ordine doar cifrele pare ale lui n, intr-un fisier &amp;quot;date.out&amp;quot;. Ex: n= 12345, Se va afisa 24;&lt;br /&gt;
&lt;br /&gt;
====Varianta1====&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 main() {&lt;br /&gt;
  int n, p, ucif, nr;&lt;br /&gt;
&lt;br /&gt;
  ///citim numarul n ca numar intreg&lt;br /&gt;
  scanf( &amp;quot;%d&amp;quot;, &amp;amp;n );&lt;br /&gt;
&lt;br /&gt;
  p = 1;&lt;br /&gt;
  nr = 0;               /// nr pe care il construim adaugand doar cifrele pare&lt;br /&gt;
  while ( n &amp;gt; 0 ){&lt;br /&gt;
    ucif = n % 10;          /// extragem ultima cifra a lui n&lt;br /&gt;
    if ( ucif % 2 == 0){    /// daca cifra este para&lt;br /&gt;
      nr = ucif * p + nr;   /// adaugam cifra para in fata numarului nr&lt;br /&gt;
      p = p * 10;           /// calculam puterea cu care trebuie sa inmultim la pasul urmator&lt;br /&gt;
    }&lt;br /&gt;
    n = n / 10;             /// taiem ultima cifra din n&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  printf( &amp;quot;%d&amp;quot;, nr );&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;
==== Varianta2 ====&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 main(){&lt;br /&gt;
  int n, p, nr, pcif;&lt;br /&gt;
  FILE *fin = fopen(&amp;quot;date.in&amp;quot;, &amp;quot;r&amp;quot;);     /// r de la read&lt;br /&gt;
  FILE *fout = fopen (&amp;quot;date.out&amp;quot;, &amp;quot;w&amp;quot;);  /// w de la write&lt;br /&gt;
  /// cititm n din fisierul de intrare&lt;br /&gt;
  fscanf(fin,&amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
&lt;br /&gt;
  ///calculeaza puterea lui 10 care aproximeaza pe n ( mai mica sau egala cu n)&lt;br /&gt;
  p = 100000000;&lt;br /&gt;
  while ( p &amp;gt; n )&lt;br /&gt;
    p = p / 10;&lt;br /&gt;
&lt;br /&gt;
  ///construiesc numarul cerut parcurgand cifrele incepand de la prima cifra a sa&lt;br /&gt;
  nr = 0;&lt;br /&gt;
  while ( p &amp;gt; 0 ){        /// ATENTIE! n&amp;gt;0 CA NU MERGE PT NUMERE CU ZEROURI LA COADA&lt;br /&gt;
    pcif = n / p;         /// extrag prima cifra din n&lt;br /&gt;
    if ( pcif % 2 == 0)   /// daca cifra este para&lt;br /&gt;
      nr = nr * 10 + pcif;/// adaug cifra la coada lui nr&lt;br /&gt;
    n = n % p;            /// scot prima cifra din n&lt;br /&gt;
    p = p / 10;           /// ajustez puterea lui 10&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  ///afisam nr in fisierul; de iesire&lt;br /&gt;
  fprintf(fout, &amp;quot;%d&amp;quot;, nr);&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;
===Eliminarea primei cifre===&lt;br /&gt;
Se citeste un numar n. Afisati numarul rezultat prin eliminarea primei cifre a lui n.&lt;br /&gt;
==== Varianta1 ====&lt;br /&gt;
Vom construi un numar nou, adaugand la noul numar toate cifrele lui n, mai putin prima cifra. &lt;br /&gt;
 &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Pseudocod&lt;br /&gt;
!C/C++&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
 integer n, p, x;&lt;br /&gt;
 read n;&lt;br /&gt;
 p ← 1;&lt;br /&gt;
 x ← 0;&lt;br /&gt;
 while (n &amp;gt; 9) do&lt;br /&gt;
   x ← (n mod 10) * p + x;  &lt;br /&gt;
   p ← p * 10;&lt;br /&gt;
   n ← n div 10;&lt;br /&gt;
 write x;&lt;br /&gt;
| &amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(){&lt;br /&gt;
  int n, p, x;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Dati un numar n:&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cin &amp;gt;&amp;gt; n;&lt;br /&gt;
  p = 1;&lt;br /&gt;
  x = 0;&lt;br /&gt;
  while (n &amp;gt; 9){&lt;br /&gt;
    x = (n % 10) * p + x;&lt;br /&gt;
    p = p * 10;&lt;br /&gt;
    n = n / 10;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Numarul rezultat este: &amp;quot; &amp;lt;&amp;lt; x;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Varianta2 ====&lt;br /&gt;
Vom calcula puterea lui 10 la care trebuie sa impartim numarul astfel incat sa eliminam prima cifra.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Pseudocod&lt;br /&gt;
!C/C++&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| &lt;br /&gt;
  integer n, p;&lt;br /&gt;
  read n;&lt;br /&gt;
  p = 1000000000;&lt;br /&gt;
  while(p&amp;gt;n)&lt;br /&gt;
    p = p / 10;&lt;br /&gt;
  write n % p;&lt;br /&gt;
| &amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(){&lt;br /&gt;
  int n, p;&lt;br /&gt;
  cin &amp;gt;&amp;gt; n;&lt;br /&gt;
  p = 1000000000;&lt;br /&gt;
  while(p&amp;gt;n)&lt;br /&gt;
    p = p / 10;&lt;br /&gt;
  cout &amp;lt;&amp;lt; n % p;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Cifra de control ===&lt;br /&gt;
Se citeste un numar n. Afisati cifra de control a numarul n. Cifra de control se obtine prin adunarea repetata a cifrelor numarului pana cand se obtine o singura cifra.&lt;br /&gt;
Ex: n=193 s=1+9+3=13 s=1+3=4 &amp;lt;br/&amp;gt;&lt;br /&gt;
Rezolvare: Vom calcula mai intai suma cifrelor lui n. Daca suma cifrelor are mai mult de o cifra, atunci copiem valoarea sumei in n si reluam calculul sumei cifrelor, de data aceasta pentru numarul obtinut prin adunarea cifrelor. Vom repeta procedeul pana cand obtinem un numar cu o singura cifra.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(){&lt;br /&gt;
  int n, s;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Dati un numar n:&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cin &amp;gt;&amp;gt; n;&lt;br /&gt;
  //calculam suma cifrelor&lt;br /&gt;
  s = 0;&lt;br /&gt;
    while( n &amp;gt; 0 ){&lt;br /&gt;
      s = s + n % 10;&lt;br /&gt;
      n = n / 10;&lt;br /&gt;
    }&lt;br /&gt;
  while( s &amp;gt; 9 ){&lt;br /&gt;
    n = s;&lt;br /&gt;
    while( n &amp;gt; 0 ){&lt;br /&gt;
      s = s + n % 10;&lt;br /&gt;
      n = n / 10;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Cifra de control este &amp;quot; &amp;lt;&amp;lt; s;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Numere palindrom apropiate de n===&lt;br /&gt;
Varianta1: Se citeste un numar n. Sa se afiseze cel mai apropiat numar palindrom fata de n, &amp;#039;&amp;#039;&amp;#039;diferit de n&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br/&amp;gt;&lt;br /&gt;
Ex1: n = 122 , afisam 121; nr 122 e cuprins intre 121 si 131, iar 121 este mai apropiat fata de 122&amp;lt;br/&amp;gt;&lt;br /&gt;
Ex2: n = 121 , afisam 111 131; 111, 131 sunt la aceeasi distanta fata de n&amp;lt;br/&amp;gt;&lt;br /&gt;
Ex3: n = 247 , afisam 242 252; 242, 252 sunt la aceeasi distanta fata de n&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(){&lt;br /&gt;
    int n, cn1, cn2, c1, c2, palin1, palin2, inv;&lt;br /&gt;
    cin&amp;gt;&amp;gt;n;               //citim n&lt;br /&gt;
    cn1=n-1;&lt;br /&gt;
    cn2=n+1;&lt;br /&gt;
    palin1 = palin2 = -1;                   //nu le-am gasit inca&lt;br /&gt;
    while (palin1 == -1 &amp;amp;&amp;amp; palin2 == -1){   //inca nu le-am gasit&lt;br /&gt;
      //verific daca cn1 e palindrom&lt;br /&gt;
      c1=cn1;&lt;br /&gt;
      inv = 0;&lt;br /&gt;
      while (c1 &amp;gt; 0){&lt;br /&gt;
        inv = inv * 10 + c1 % 10;&lt;br /&gt;
        c1 = c1 /10; //div&lt;br /&gt;
      }&lt;br /&gt;
      if (cn1 == inv ){&lt;br /&gt;
        palin1 = cn1;&lt;br /&gt;
      }&lt;br /&gt;
      //verific daca cn2 e palindrom&lt;br /&gt;
      c2=cn2;&lt;br /&gt;
      inv = 0;&lt;br /&gt;
      while (c2 &amp;gt; 0){&lt;br /&gt;
        inv = inv * 10 + c2 % 10;&lt;br /&gt;
        c2 = c2 /10; //div&lt;br /&gt;
      }&lt;br /&gt;
      if (cn2 == inv ){&lt;br /&gt;
        palin2 =cn2;&lt;br /&gt;
      }&lt;br /&gt;
      cn1 = cn1-1;&lt;br /&gt;
      cn2 = cn2+1;&lt;br /&gt;
    }&lt;br /&gt;
    if (palin1!=-1 &amp;amp;&amp;amp; palin2!=-1)   //cand am gasit 2 la aceeasi distanta&lt;br /&gt;
      cout&amp;lt;&amp;lt;palin1&amp;lt;&amp;lt;palin2;&lt;br /&gt;
    else if (palin1!=-1)            //daca am gasit doar pe palin1&lt;br /&gt;
      cout&amp;lt;&amp;lt;palin1;&lt;br /&gt;
    else&lt;br /&gt;
      cout&amp;lt;&amp;lt;palin2;&lt;br /&gt;
&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;
Varianta2: Se citeste un numar n. Sa se afiseze cel mai apropiat numar palindrom fata de n.&amp;lt;br/&amp;gt;&lt;br /&gt;
Ex1: n = 122 , afisam 121; nr 122 e cuprins intre 121 si 131, iar 121 este mai apropiat fata de 122&amp;lt;br/&amp;gt;&lt;br /&gt;
Ex2: n = 121 , afisam 121 &amp;lt;br/&amp;gt;&lt;br /&gt;
Ex3: n = 247 , afisam 242 252; 242 si 252 sunt la aceeasi distanta fata de n&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(){&lt;br /&gt;
    int n, cn1, cn2, c1, c2, palin1, palin2, inv;&lt;br /&gt;
    cin&amp;gt;&amp;gt;n;               //citim n&lt;br /&gt;
    cn1=n;&lt;br /&gt;
    cn2=n;&lt;br /&gt;
    palin1 = palin2 = -1;                   //nu le-am gasit inca&lt;br /&gt;
    while (palin1 == -1 &amp;amp;&amp;amp; palin2 == -1){   //inca nu le-am gasit&lt;br /&gt;
      //verific daca cn1 e palindrom&lt;br /&gt;
      c1=cn1;&lt;br /&gt;
      inv = 0;&lt;br /&gt;
      while (c1 &amp;gt; 0){&lt;br /&gt;
        inv = inv * 10 + c1 % 10;&lt;br /&gt;
        c1 = c1 /10; //div&lt;br /&gt;
      }&lt;br /&gt;
      if (cn1 == inv ){&lt;br /&gt;
        palin1 = cn1;&lt;br /&gt;
      }&lt;br /&gt;
      //verific daca cn2 e palindrom&lt;br /&gt;
      c2=cn2;&lt;br /&gt;
      inv = 0;&lt;br /&gt;
      while (c2 &amp;gt; 0){&lt;br /&gt;
        inv = inv * 10 + c2 % 10;&lt;br /&gt;
        c2 = c2 /10; //div&lt;br /&gt;
      }&lt;br /&gt;
      if (cn2 == inv ){&lt;br /&gt;
        palin2 =cn2;&lt;br /&gt;
      }&lt;br /&gt;
      cn1 = cn1-1;&lt;br /&gt;
      cn2 = cn2+1;&lt;br /&gt;
    }&lt;br /&gt;
    if (palin1!=-1 &amp;amp;&amp;amp; palin2!=-1){   //cand am gasit 2 la aceeasi distanta&lt;br /&gt;
      if(palin1 == palin2)           //cand &lt;br /&gt;
        cout&amp;lt;&amp;lt;palin1;&lt;br /&gt;
      else&lt;br /&gt;
      cout&amp;lt;&amp;lt;palin1&amp;lt;&amp;lt;&amp;quot; &amp;quot;&amp;lt;&amp;lt;palin2;&lt;br /&gt;
    }&lt;br /&gt;
      &lt;br /&gt;
    else if (palin1!=-1)            //daca am gasit doar pe palin1&lt;br /&gt;
      cout&amp;lt;&amp;lt;palin1;&lt;br /&gt;
    else&lt;br /&gt;
      cout&amp;lt;&amp;lt;palin2;&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;
= Test = &lt;br /&gt;
Test din pbinfo: &lt;br /&gt;
= Tema7 = &lt;br /&gt;
Alegeti 3 probleme din runda:&lt;br /&gt;
* [http://varena.ro/runda/temas7_5 Tema7_varena]&lt;br /&gt;
Incercati sa rezolvati acasa problemele din test: &lt;br /&gt;
* S7 Problemele din test&lt;br /&gt;
Optional:&lt;br /&gt;
Rezolvati si celelalte 3 probleme din runda din varena&lt;/div&gt;</summary>
		<author><name>Bella</name></author>
	</entry>
</feed>