Given two arrays, first has 'n' numbers and the second one has 'n-m' numbers; the second array is not in the same order as the first. If there are several numbers with the same value, they end up in the order of the positions in the original array. Also, all the values from the second array are also found in the first array. I have to find the 'm' missing numbers in the order in which they appear in the first array.
input:
7 3
12 34 45 29 100 87 32
100 87 12 34
output:
45 29 32
#include <iostream>
using namespace std;
int main()
{
int n, missing_number = 0, m, i, j, v[1201], w[1201];
cin >> n >> m;
for (i = 0; i < n; ++i) {
cin >> v[i];
}
for (i = 0; i < n - m; ++i) {
cin >> w[i];
}
for (i = 0; i < n; ++i) {
missing_number = 1;
for (j = 0; j < n - m; ++j) {
if (v[i] == w[j]) {
missing_number = -1;
}
}
if (missing_number == 1) {
cout << v[i] << " ";
}
}
if (m == 0)
cout << "there are no missing numbers";
return 0;
}
my code doesn't work for repeating numbers like:
7 3
2 6 1 9 3 2 4
4 1 2 3
where my output should be:
6 9 2