Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. long long clase[10010], pachete[10010];
  6.  
  7. ifstream f("clase.in");
  8. ofstream g("clase.out");
  9.  
  10. int main()
  11. {
  12. int n, m, st, dr, mij, contor = 0;
  13. f >> n;
  14. for(int i = 1; i <= n; i++)
  15. {
  16. f >> clase[i];
  17. }
  18. f >> m;
  19. for(int i = 1; i <= m; i++)
  20. {
  21. f >> pachete[i];
  22. }
  23.  
  24. for(int i = 1; i <= m; i++)
  25. {
  26. st = 1;
  27. dr = n;
  28.  
  29. while(st <= dr)
  30. {
  31. mij = (st + dr) / 2;
  32. if(clase[mij] == pachete[i])
  33. {
  34. // cout << pachete[i] << endl;
  35. contor++;
  36. st = dr + 1;
  37. }
  38. if(pachete[i] < clase[mij] )
  39. {
  40. dr = mij - 1;
  41. }
  42. if(pachete[i] > clase[mij]) {
  43. st = mij + 1;
  44. }
  45. }
  46. }
  47. g << contor;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement