Advertisement
hopingsteam

Untitled

Oct 8th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. /*
  2. Un sir dat de n numerele naturale, orice numar natural din intervalul inchis 0-1000000000 fie nu apare niciodata, fie apare de un numar de c ori care este multiplu de k(dat). Exceptie facem un singur numar care apare de un x de ori ce nu este multiplu de k.
  3. Scrieti un program care determina numarul cautat.
  4.  
  5. 13
  6. 2
  7. 1 1 2 2 3 3 3 3 4 4 4 5 5
  8. */
  9. #include    <iostream>
  10. #include    <fstream>
  11.  
  12. using namespace std;
  13.  
  14. ifstream fin("heapuri.in");
  15.  
  16. int n,k;
  17.  
  18. int main()
  19. {
  20.     fin >> n;
  21.     fin >> k;
  22.  
  23.     int valoare_veche = -1;
  24.     int contor = 1;
  25.  
  26.     for(int i = 1; i <= n; i++)
  27.     {
  28.         int x;
  29.         fin >> x;
  30.  
  31.         if(x != valoare_veche)
  32.         {
  33.             //cout << "[DEBUG]: contor schimbat. Am intalnit " << valoare_veche << " de " << contor << " ori. ";
  34.             if(contor % k && valoare_veche != -1) // daca nu se imparte
  35.                 cout << valoare_veche << " - nu respecta";
  36.             contor = 1;
  37.         }
  38.         else
  39.             contor++;
  40.  
  41.         valoare_veche = x;
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement