Răspuns :
Răspuns:
#include <iostream>
#include <fstream>
using namespace std;
void sortare(int c[], int k){
int i, j;
int aux;
for (i = 0;i < k; i++)
for (j = 0;j < k-1; j++)
if (c[i] < c[j]){
aux = c[i];
c[i] = c[j];
c[j] = aux;
}
}
void eliminare(int c[], int &k){
int i, j;
int x;
for (i = 0;i < k; i++)
for (j = i+1;j < k; j++)
if (c[i] == c[j]){
for (x = j;x < k; x++)
c[x] = c[x+1];
k--;
}
}
int main(){
ifstream fin("BAC.TXT");
int n, m;
int i, j;
int a[1000];
int b[1000];
int c[1000];
int k;
fin >> n >> m;
for (i = 0;i < n; i++)
fin >> a[i];
for (j = 0;j < m; j++)
fin >> b[j];
fin.close();
cout << "Sirul a:\n";
for (i = 0;i < n; i++)
cout << a[i] << ' ';
cout << endl << "Sirul b:\n";
for (j = 0;j < m; j++)
cout << b[j] << ' ';
cout << endl;
for (j = 0;j < m; j++){
int nr = b[j];
for (i = 0;i < n; i++)
if (nr > a[i] && nr < a[i+1]){
c[k] = nr;
k++;
}
if (nr < a[0]){
c[k] = nr;
k++;
}
if (nr > a[n-1]){
c[k] = nr;
k++;
}
}
sortare(c,k);
eliminare(c,k);
if (k > 0){
cout << "Elementele care pot fi inserare in sirul 'a' conform conditiilor specificate:\n";
for (i = 0;i < k; i++)
cout << c[i] << ' ';
cout << endl;
}
else
cout << "Nu sunt elemente care pot fi inserate in sirul 'a'\n";
return 0;
}
Explicație: