Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("interclasare3.in");
  6. ofstream fout("interclasare3.out");
  7.  
  8. int main()
  9. {
  10. int a[100001], b[100001], c[200002], n, m, k = 0;
  11. fin >> n >> m;
  12. for(int i = 1; i <= n; ++i)
  13. fin >> a[i];
  14.  
  15.  
  16. for (int j = 1; j <= m; ++j)
  17. fin >> b[j];
  18.  
  19. int x = 1, y = m;
  20.  
  21. while (x <= n && y >= 1)
  22. if( a[x] % 2 == 0 )
  23. {
  24. if( b[y] % 2 == 0)
  25. {
  26. if( a[x] < b[y] )
  27. {
  28. ++k;
  29. c[k] = a[x];
  30. x++;
  31. }
  32. else
  33. {
  34. ++k;
  35. c[k] = b[y];
  36. --y;
  37. }
  38. }
  39. else
  40. {
  41. while( b[y] % 2 == 1)--y;
  42. }
  43. }
  44. else
  45. {
  46. while( a[x] % 2 == 1 ) ++x;
  47. }
  48.  
  49. while (x <= n )
  50. {
  51. if( a[x] % 2 == 0 )
  52. {
  53. ++k;
  54. c[k] = a[x];
  55. ++x;
  56. }
  57. else ++x;
  58. }
  59. while (y > 0 )
  60. {
  61. if( b[y] % 2 == 0 )
  62. {
  63. ++k;
  64. c[k] = b[y];
  65. --y;
  66. }
  67. else --y;
  68. }
  69.  
  70. for(int i = 1; i <= k; ++i)
  71. {
  72. fout << c[i] << " ";
  73. if( i % 20 == 0) fout << '\n';
  74. }
  75.  
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement