Advertisement
a53

intersectie_siruri

a53
Dec 17th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int a[100005], b[100005], c[100005], ct, ct2, ct3, i, j;
  4. int main()
  5. {
  6. ifstream f("intersectie.in");
  7. ofstream g("intersectie.out");
  8. a[0] = 1;
  9. while(a[ct] != 0)
  10. f >> a[++ct];
  11. ct--;
  12. while(f >> b[1])
  13. {
  14. ct2 = 1;
  15. ct3 = 0;
  16. while(b[ct2] != 0)
  17. f >> b[++ ct2];
  18. i = j = 1;
  19. while(i <= ct && j <= ct2)
  20. {
  21. if(a[i] == b[j]) c[++ ct3] = b[j], j++, i++;
  22. else if(a[i] > b[j]) j++;
  23. else i++;
  24. }
  25. for(i = 1; i <= ct3; i++)
  26. a[i] = c[i];
  27. ct = ct3;
  28. if(ct3 == 0)
  29. {
  30. g << "nu exista";
  31. return 0;
  32. }
  33. }
  34. for(i = 1; i <= ct3; i++)
  35. g << a[i] << " ";
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement