Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define N 5
- #define M 6
- int main () {
- int cont=0;
- int Negozio[N][2] = {{1, 10},
- {2, 11},
- {5, 4},
- {7, 5}};
- int Magazino[N][2] = {{2, 20},
- {3, 11},
- {5, 7},
- {8, 8},
- {10, 10}};
- int Totale[M+N][2];
- int a=0, i, b=0;
- i=0;
- while (a<N or b<M) {
- if (Negozio[a][0]==Magazino[b][0] and b<M-1 and a<N-1) {
- Totale[i][0]=Negozio[a][0];
- Totale[i][1]=Magazino[b][1]+Negozio[a][1]; cout<<"a="<<a<<" b="<<b<<endl;
- a++; b++; cont++;
- }
- if ((Negozio[a][0]>Magazino[b][0] or a==N-1) and b<M) {
- Totale[i][0]=Magazino[b][0];
- Totale[i][1]=Magazino[b][1]; cout<<"b="<<b<<endl;
- b++; cont++;
- }
- if ((Negozio[a][0]<Magazino[b][0] or b==M-1) and a<N){
- Totale[i][0]=Negozio[a][0];
- Totale[i][1]=Negozio[a][1]; cout<<"a="<<a<<endl;
- a++; cont++;
- }
- }
- cout<<endl<<endl;
- for (int i=0; i<cont; i++) {
- for (int j=0; j<2; j++) {
- cout.width(4);
- cout<<Totale[i][j]<<" ";
- }
- cout<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment