Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream fin("interclasare3.in");
- ofstream fout("interclasare3.out");
- int main()
- {
- int a[100001], b[100001], c[200002], n, m, k = 0;
- fin >> n >> m;
- for(int i = 1; i <= n; ++i)
- fin >> a[i];
- for (int j = 1; j <= m; ++j)
- fin >> b[j];
- int x = 1, y = m;
- while (x <= n && y >= 1)
- if( a[x] % 2 == 0 )
- {
- if( b[y] % 2 == 0)
- {
- if( a[x] < b[y] )
- {
- ++k;
- c[k] = a[x];
- x++;
- }
- else
- {
- ++k;
- c[k] = b[y];
- --y;
- }
- }
- else
- {
- while( b[y] % 2 == 1)--y;
- }
- }
- else
- {
- while( a[x] % 2 == 1 ) ++x;
- }
- while (x <= n )
- {
- if( a[x] % 2 == 0 )
- {
- ++k;
- c[k] = a[x];
- ++x;
- }
- else ++x;
- }
- while (y > 0 )
- {
- if( b[y] % 2 == 0 )
- {
- ++k;
- c[k] = b[y];
- --y;
- }
- else --y;
- }
- for(int i = 1; i <= k; ++i)
- {
- fout << c[i] << " ";
- if( i % 20 == 0) fout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement