Advertisement
Norby9

Untitled

Feb 21st, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("date.in");
  8.  
  9. int n, m, a[3001], b[3001], i, j, x, n1, m1;
  10.  
  11. int main() {
  12. cin >> n >> m;
  13. for(i = 1; i <= n; i ++) {
  14. cin >> x;
  15. if(x % 2 == 0)
  16. a[++ n1] = x;
  17. }
  18. for(j = 1; j <= m; j ++) {
  19. cin >> x;
  20. if(x % 2 == 0)
  21. b[++ m1] = x;
  22. }
  23. i = 1;
  24. j = m1;
  25. while(i <= n1 && j >= 1) {
  26. if(a[i] < b[j]) {
  27. cout << a[i] << " ";
  28. i ++;
  29. } else if(a[i] > b[j]) {
  30. cout << b[j] << " ";
  31. j --;
  32. } else {
  33. cout << a[i] << " " << b[j] << " ";
  34. i ++;
  35. j --;
  36. }
  37. }
  38. while(i <= n1) {
  39. cout << a[i] << " ";
  40. i ++;
  41. }
  42. while(j >= 1) {
  43. cout << b[j] << " ";
  44. j --;
  45. }
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement