Răspuns :
Răspuns:
#include <iostream>
#include <fstream>
#include <bitset>
using namespace std;
bitset<1000001>a;
int main()
{
ifstream f("interclasare1.in");
ofstream g("interclasare1.out");
int n, m, i, num, k=0;
f >> n ;
for (i=1; i<=n; ++i)
{
f>> num; a[num]=1;
}
f >> m;
for (i=1; i<=m; ++i)
{
f >> num; a[num]=1;
}
for (i=0; i<=1000000; ++i)
{
if (a[i]==1)
{
++k; if (k%10) g<< i << " ";
else g<< i << "\n";
}
}
return 0;
}
Explicație:
#include <bits/stdc++.h>
using namespace std;
ifstream fin("interclasare1.in");
ofstream fout("interclasare1.out");
int n, m, a[100002], b[100002], c[200004];
int main() {
fin >> n;
for (int i = 1; i <= n; i++)
fin >> a[i];
fin >> m;
for (int i = 1; i <= m; i++)
fin >> b[i];
int i = 1, j = 1, k = 1;
while (i <= n && j <= m) {
if (a[i] < b[j]) {
c[k++] = a[i++];
}
else {
if (a[i] > b[j]) {
c[k++] = b[j++];}
else ++i;
}
}
while(i <= n)
c[k ++] = a[i ++];
while(j <= m)
c[k ++] = b[j ++];
for (int i = 1; i < k; i++) {
fout << c[i] << " ";
if (i % 10 == 0)
fout << endl;
}
}