Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- vector<double> concatenacio(vector<double> v, double n){
- int x=v.size();
- vector<double> nou(x+1);
- for (int i=0;i< x;i++) nou[i]=v[i];
- nou[x]=n;
- return nou;
- }
- vector<double> difference(const vector<double>& v1, const vector<double>& v2){
- int n=v1.size(), m=v2.size(), start=0;
- bool sierto=true;
- vector<double> v(0);
- while((v1[0]<=v2[start])and (start<m) and sierto){
- if(v1[0]==v2[start]) sierto=false;
- else start++;
- }
- if(sierto) v=concatenacio(v,v1[0]);
- for (int i=1;i<n;i++){
- while((v1[i]==v1[i-1]) and i<n)i++;
- if(i!=n){
- int j=0;
- bool sierto=true;
- while((j<m)and sierto){
- if (v1[i]==v2[j]) sierto=false;
- else j++;
- if (v1[i]< v2[j]) j=m;
- }
- if(sierto) v=concatenacio(v,v1[i]);
- }
- }
- return v;
- }
- int main(){
- int n,m;
- cin >> n >> m;
- vector<double> v1(n),v2(m);
- for (int i=0;i<n;i++) cin >> v1[i];
- for (int i=0;i<m;i++) cin >> v2[i];
- vector<double> v=difference(v1,v2);
- int x= v.size();
- for (int i=0;i<x;i++) cout << v[i] << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement