Advertisement
LoGoFiOS

Untitled

Jul 25th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. int main(){
  2.  
  3.     const int row = 5;
  4.     const int col = 10;
  5.     vector <int> vectorOne;
  6.     vector <vector <int>> vectorTwo;
  7.  
  8. // попытка сделать через итераторы
  9.     vectorTwo.resize(row);
  10.     for (vector<vector<int>>::iterator x = vectorTwo.begin(); x != vectorTwo.end(); ++x){
  11.         (*x).resize(col);
  12.         for (vector<int>::iterator y = vectorOne.begin(); y != vectorOne.end(); ++y){
  13.             (*y).push_back(2);
  14.         }
  15.         vectorTwo.push_back(vectorOne);
  16.         vectorOne.clear();
  17.     }
  18.  
  19. // через известные размерности
  20.     vectorTwo.resize(row);
  21.     for (decltype(vectorTwo.size()) x = 0; x != row; ++x){
  22.         vectorTwo[x].resize(col);
  23.         for (decltype(vectorTwo[x].size()) y = 0; y != col; ++y){
  24.             vectorOne.push_back(x+y+2*x);
  25.             cout << vectorOne[y] << " ";
  26.         }
  27.         cout << endl;
  28.         vectorTwo.push_back(vectorOne);
  29.         vectorOne.clear();
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement