Advertisement
kompilainenn

Untitled

Apr 22nd, 2022
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <string>
  2. #include <vector>
  3.  
  4. std::vector<std::string> towerBuilder(unsigned nFloors) {
  5.   std::vector<std::string> piramid;
  6.  
  7.   for (unsigned int i = 0; i < nFloors; i++){
  8.     std::string str = "";
  9.     int nStars = i * 2 + 1;
  10.     int nSpaces = nFloors-1-i;
  11.     str.append(nSpaces, ' ');
  12.     str.append(nStars, '*');
  13.     str.append(nSpaces, ' ');
  14.     piramid[i] = str;
  15.   };  
  16.   return piramid;
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement