You are on page 1of 5

#include<iostream>

using namespace std;


int main()
{int x[100], y[100], z[200], j, i, n, m, k;
cout << "n = "; cin >> n;
cout << "m = "; cin >> m;
cout << "x[1] = "; cin >> x[1];
for(i = 2; i <= n; i++)
do
{cout << "x[" << i << "]= "; cin >> x[i];}
while(x[i] <= x[i - 1]);
cout << "y[1]= "; cin >> y[1];
for(i = 2; i <= m; i++)
do
{cout << "y[" << i << "]= "; cin >> y[i];}
while(y[i] <= y[i - 1]);
i = 1; j = 1; k = 0;
while(i <= n && j <= m)
if (x[i] < y[j])
{k++;
z[k] = x[i];
i++;
}
else
{k++;
z[k] = y[j];
j++;
}
if (i<=n)
while(i <= n)
{k++;
z[k] = x[i];
i++;
}
if (j<=m)
while(j <= m)
{k++;
z[k] = y[j];
j++;
}
cout << "Vectorul sortat este ";
for (i = 1; i <= k; i++) cout << z[i] << " ";
return 0;}

__________________________________________________________________________________________________
#241
100 puncte

#include <iostream>
#include <fstream>
using namespace std;

int
main ()
{
ifstream f("interclasare.in");
ofstream g("interclasare.out");
int n, m, i, j, k, a[100001], b[100001], c[200001];
f >> n;
for (i = 1; i <= n; i++)
f >> a[i];
f >> m;
for (j = 1; j <= m; j++)
f >> b[j];
i = 1;
j = 1;
k = 0;
while (i <= n && j <= m)
if (a[i] < b[j])
{c[++k] = a[i]; i++;}
else if (b[j] < a[i])
{c[++k] = b[j]; j++;}
else {c[++k] = a[i]; i++; c[++k] = b[j]; j++;}
while (i <= n) {c[++k] = a[i]; i++;}
while (j <= m) {c[++k] = b[j]; j++;}
for (i = 1; i <= k; i++)
{
g << c[i] << " ";
if (i % 10 == 0) g << endl;
}
f.close();
g.close();
return 0;
}

#251
100 puncte

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ifstream f("interclasare2.in");
ofstream g("interclasare2.out");
int n, m, a[100001], b[100001], c[200001], i, j, k;
f >> n;
for (i = 1; i <= n; i++)
f >> a[i];
f >> m;
for (j = 1; j <= m; j++)
f >> b[j];
i = 1;
j = 1;
k = 0;
while (i <= n && j <= m)
if (a[i] < b[j])
{ i++;}
else if (b[j] < a[i])
{j++;}
else {c[++k] = a[i]; i++; j++;}

for (i = 1; i <= k; i++)


{
g << c[i] << " ";
if (i % 10 == 0) g << endl;
}
f.close();
g.close();
return 0;
}

#250

100 puncte

#include <iostream>
#include <fstream>
using namespace std;

int
main ()
{
ifstream f("interclasare1.in");
ofstream g("interclasare1.out");
int n, m, i, j, k, a[100001], b[100001], c[200001];
f >> n;
for (i = 1; i <= n; i++)
f >> a[i];
f >> m;
for (j = 1; j <= m; j++)
f >> b[j];
i = 1;
j = 1;
k = 0;
while (i <= n && j <= m)
if (a[i] < b[j])
{c[++k] = a[i]; i++;}
else if (b[j] < a[i])
{c[++k] = b[j]; j++;}
else {c[++k] = a[i]; i++; j++;}
while (i <= n) {c[++k] = a[i]; i++;}
while (j <= m) {c[++k] = b[j]; j++;}
for (i = 1; i <= k; i++)
{
g << c[i] << " ";
if (i % 10 == 0) g << endl;
}
f.close();
g.close();
return 0;
}

You might also like