Guest User

Untitled

a guest
Feb 9th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define N 5
  4. #define M 6
  5.  
  6. int main () {
  7.     int cont=0;
  8.     int Negozio[N][2] = {{1, 10},
  9.                          {2, 11},
  10.                          {5, 4},
  11.                          {7, 5}};
  12.    
  13.     int Magazino[N][2] = {{2, 20},
  14.                           {3, 11},
  15.                           {5, 7},
  16.                           {8, 8},
  17.                           {10, 10}};
  18.    
  19.     int Totale[M+N][2];
  20.     int a=0, i, b=0;
  21.     i=0;
  22.    
  23.     while (a<N or b<M) {
  24.         if (Negozio[a][0]==Magazino[b][0] and b<M-1 and a<N-1) {
  25.             Totale[i][0]=Negozio[a][0];
  26.             Totale[i][1]=Magazino[b][1]+Negozio[a][1];          cout<<"a="<<a<<"   b="<<b<<endl;
  27.             a++; b++; cont++;  
  28.         }
  29.        
  30.         if ((Negozio[a][0]>Magazino[b][0] or a==N-1) and b<M)  {
  31.             Totale[i][0]=Magazino[b][0];
  32.             Totale[i][1]=Magazino[b][1];                        cout<<"b="<<b<<endl;
  33.             b++;    cont++;                                                
  34.         }
  35.        
  36.         if ((Negozio[a][0]<Magazino[b][0] or b==M-1) and a<N){
  37.             Totale[i][0]=Negozio[a][0];
  38.             Totale[i][1]=Negozio[a][1];                         cout<<"a="<<a<<endl;
  39.             a++;    cont++;                                        
  40.         }
  41.     }
  42.  
  43.     cout<<endl<<endl;
  44.     for (int i=0; i<cont; i++) {
  45.         for (int j=0; j<2; j++) {
  46.             cout.width(4);
  47.             cout<<Totale[i][j]<<" ";
  48.         }
  49.     cout<<endl;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment