a53

Memory010

a53
Dec 19th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. unsigned int v[940000]; /// suficienti biti pentru a reprezenta orice valoare intre 0 si 30 mil
  4. unsigned int duplicat;
  5.  
  6. int adauga (unsigned int x)
  7. {
  8. int poz1 = x/32; /// al catelea element din vectorul v va contine bitul cu numarul x
  9. int poz2 = x%32; /// al catelea bit din v[poz1] este bitul al x-ulea
  10. unsigned int i=1;
  11. if (v[poz1] & (i<<poz2)) return 0;
  12. v[poz1] |= (i<<poz2);
  13. return 1;
  14. }
  15.  
  16. int main()
  17. {
  18. bool gasit=false;
  19. while(!gasit)
  20. {
  21. int x;
  22. cin >> x;
  23. if (!adauga(x))
  24. {
  25. duplicat=x;
  26. gasit=true;
  27. }
  28. }
  29. cout << duplicat;
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment