Advertisement
SamuelKostadinov

Es

Mar 26th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int& TV(int* p, int lim1, int lim2, int lim3, int f, int n){
  5.     return *(p + n * lim3 + f);
  6. }
  7.  
  8. int main()
  9. {
  10.     int x[100];
  11.     for(int i=0; i<100; i++){
  12.         cin >> x[i];  
  13.     }
  14.     int lim1, lim2, lim3;
  15.     int arr[4];
  16.     cin >> lim1 >> lim2 >> lim3;
  17.     cout<<"start"<<endl;
  18.     // ciclo che invoca TV da fare
  19.     int w = 0;
  20.     int* p = x;
  21.     int r = 0;
  22.     int aux;
  23.    
  24.     while(r != -1){
  25.         cin>>r;
  26.         if(r != -1){
  27.             arr[w] = r;
  28.             w++;
  29.         }
  30.         if(w == 4){
  31.             int & el = TV(p, lim1, lim2, lim3, arr[0], arr[1]);
  32.             int & el2 = TV(p, lim1, lim2, lim3, arr[2], arr[3]);
  33.             aux = el;
  34.             el = el2;
  35.             el2 = aux;
  36.         }
  37.         if(w == 4){
  38.             w = w - 4;
  39.         }
  40.        
  41.     }
  42.    
  43.     w = 0;
  44.    
  45.     for(int i = 0; i < lim1; i++){
  46.        for(int j = 0; j < lim2; j++){
  47.             for(int k = 0; k < lim3; k++){
  48.                 cout<<x[w]<<" ";
  49.                 w++;
  50.             }
  51.             cout<<endl;
  52.         }
  53.         cout<<endl;
  54.     }
  55.  
  56.   cout<<"end";
  57.  
  58.   return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement