csansoon

Consolidation 3.03 P43260 Cruz recursiva

Dec 28th, 2018
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. void print(vector <vector <char> >& v) {for (int i=0; i<v.size(); ++i) {cout<<"|"; for (int j=0; j<v[0].size(); ++j){cout<<v[i][j];} cout<<"|"<<endl;}}
  5.  
  6.  
  7.  
  8.  
  9. vector <vector <char> > cruz_recursiva(vector <vector <char> >& v, int n) {
  10.     if (n==0) return v;
  11.     int vx=v[0].size(), vy=v.size();
  12.     vector <vector <char> > c((3*vy), vector <char> ((3*vx),' '));
  13.     int x, y;
  14.    
  15.     x=vx;
  16.     y=0;
  17.     for (int i=0; i<vy; ++i) for (int j=0; j<vx; ++j) c[i+y][j+x] = v[i][j];
  18.    
  19.     x=0;
  20.     y=vy;
  21.     for (int i=0; i<vy; ++i) for (int j=0; j<vx; ++j) c[i+y][j+x] = v[i][j];
  22.    
  23.     x=vx;
  24.     y=vx;
  25.     for (int i=0; i<vy; ++i) for (int j=0; j<vx; ++j) c[i+y][j+x] = v[i][j];
  26.    
  27.     x=vx*2;
  28.     y=vy;
  29.     for (int i=0; i<vy; ++i) for (int j=0; j<vx; ++j) c[i+y][j+x] = v[i][j];
  30.    
  31.     x=vx;
  32.     y=vy*2;
  33.     for (int i=0; i<vy; ++i) for (int j=0; j<vx; ++j) c[i+y][j+x] = v[i][j];
  34.    
  35.     return cruz_recursiva(c,n-1);
  36. }
  37.  
  38.  
  39. int main() {
  40.     vector <vector <char> > v(3, vector <char> (3, ' '));
  41.     v[0][1]='|';
  42.     v[2][1]='|';
  43.     v[1][1]='O';
  44.     v[1][0]='-';
  45.     v[1][2]='-';
  46.     int n;
  47.     cin>>n;
  48.    
  49.    
  50.     vector <vector <char> > c = cruz_recursiva(v,n-1);
  51.    
  52.     print(c);
  53. }
  54.  
  55. // (c) Carlos Sansón (Best pro1 delegate ever for sure) @csansoon
Advertisement
Add Comment
Please, Sign In to add comment