Advertisement
Guest User

DIFERENCIA DE TAULES

a guest
Jul 10th, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. vector<double> concatenacio(vector<double> v, double n){
  6.     int x=v.size();
  7.     vector<double> nou(x+1);
  8.     for (int i=0;i< x;i++) nou[i]=v[i];
  9.     nou[x]=n;
  10.     return nou;
  11. }
  12.  
  13. vector<double> difference(const vector<double>& v1, const vector<double>& v2){
  14.     int n=v1.size(), m=v2.size(), start=0;
  15.     bool sierto=true;
  16.     vector<double> v(0);
  17.     while((v1[0]<=v2[start])and (start<m) and sierto){
  18.         if(v1[0]==v2[start]) sierto=false;
  19.         else start++;
  20.     }
  21.     if(sierto) v=concatenacio(v,v1[0]);
  22.     for (int i=1;i<n;i++){
  23.         while((v1[i]==v1[i-1]) and i<n)i++;
  24.         if(i!=n){
  25.             int j=0;
  26.             bool sierto=true;
  27.             while((j<m)and sierto){
  28.                 if (v1[i]==v2[j]) sierto=false;
  29.                 else j++;
  30.                 if (v1[i]< v2[j]) j=m;
  31.             }
  32.             if(sierto) v=concatenacio(v,v1[i]);
  33.         }
  34.     }
  35.     return v;
  36. }
  37.  
  38. int main(){
  39.     int n,m;
  40.     cin >> n >> m;
  41.     vector<double> v1(n),v2(m);
  42.     for (int i=0;i<n;i++) cin >> v1[i];
  43.     for (int i=0;i<m;i++) cin >> v2[i];
  44.     vector<double> v=difference(v1,v2);
  45.     int x= v.size();
  46.     for (int i=0;i<x;i++) cout << v[i] << " ";
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement