Advertisement
CotoiRares

Untitled

Mar 24th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <iomanip>
  2. #include <fstream>
  3. #include <iostream>
  4. #include <cassert>
  5. using namespace std;
  6.  
  7. ifstream fin("interclasm.in");
  8. ofstream fout("interclasm.out");
  9.  
  10. int a[100005],n, b[100005], m, c[200005], k;
  11.  
  12. int main(){
  13. int x;
  14. fin >> x;
  15. fin >> n;
  16. for(int i=1;i<=n;++i){
  17. fin >> a[i];
  18. }
  19. fin >> m;
  20. for(int i=1;i<=m;++i){
  21. fin >> b[i];
  22. }
  23. int i=1,j=1;
  24. k = 0;
  25. while(i<=n && j<=m)
  26. if(a[i]<b[j])
  27. if(a[i]%x == 0)
  28. c[++k] = a[i] , i++;
  29. else
  30. i++;
  31. else
  32. if(a[i]>b[j])
  33. if(b[j]%x == 0)
  34. c[++k] = b[j] , j++;
  35. else
  36. j++;
  37. else
  38. i++, j++;
  39. if(i<=n)
  40. while(i<=n)
  41. if(a[i]%x == 0)
  42. c[++k] = a[i] , i++;
  43. else
  44. i++;
  45. else
  46. while(j<=m)
  47. if(b[j]%x == 0)
  48. c[++k] = b[j] , j++;
  49. else
  50. j++;
  51. for(int i=1;i<=k;++i)
  52. {
  53. fout << c[i] << " ";
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement