Răspuns :
la a) poti scrie despre complexitatea liniara a algoritmului.
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("bac.in");
int v[1001],x[1001],i,j,m,n,ok;
int main()
{
fin>>m>>n;
for (i=1;i<=m;i++)
fin>>v[i];
for (i=1;i<=n;i++)
fin>>x[i];
i=m;
j=n;
while (i && j)
{
if (v[i]==x[j] && v[i]%2==0)
{
ok=1;
cout<<v[i]<<" ";
i--; j--;
}
else
{
if (v[i]>x[j])
{
if (v[i]%2==0)
{
ok=1;
cout<<v[i]<<" ";
}
i--;
}
else
{
if (x[j]%2==0)
{
ok=1;
cout<<x[j]<<" ";
}
j--;
}
}
}
if (i && !j)
{
while (i)
{
if (v[i]%2==0)
{
ok=1;
cout<<v[i]<<" ";
}
i--;
}
}
else
{
while (j)
{
if (x[j]%2==0)
{
ok=1;
cout<<x[j]<<" ";
}
i--;
}
}
return 0;
}
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("bac.in");
int v[1001],x[1001],i,j,m,n,ok;
int main()
{
fin>>m>>n;
for (i=1;i<=m;i++)
fin>>v[i];
for (i=1;i<=n;i++)
fin>>x[i];
i=m;
j=n;
while (i && j)
{
if (v[i]==x[j] && v[i]%2==0)
{
ok=1;
cout<<v[i]<<" ";
i--; j--;
}
else
{
if (v[i]>x[j])
{
if (v[i]%2==0)
{
ok=1;
cout<<v[i]<<" ";
}
i--;
}
else
{
if (x[j]%2==0)
{
ok=1;
cout<<x[j]<<" ";
}
j--;
}
}
}
if (i && !j)
{
while (i)
{
if (v[i]%2==0)
{
ok=1;
cout<<v[i]<<" ";
}
i--;
}
}
else
{
while (j)
{
if (x[j]%2==0)
{
ok=1;
cout<<x[j]<<" ";
}
i--;
}
}
return 0;
}