Advertisement
kompilainenn

Untitled

Apr 21st, 2022
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <string>
  2. #include <vector>
  3. #include <iostream>
  4.  
  5. std::vector<std::string> towerBuilder(unsigned nFloors) {
  6.   std::vector<std::string> piramid;
  7.   for (unsigned int i = 0; i < nFloors; i++){
  8.     piramid[i].append(nFloors/2-1-i, ' ');
  9.     piramid[i].append(i*2+1, '*');
  10.     piramid[i].append(nFloors/2-1-i, ' ');
  11.   };  
  12.   return piramid;
  13. }
  14.  
  15. int main(){
  16.    
  17.     std::vector<std::string> result;
  18.     unsigned x;
  19.     std::cin >> x;
  20.     result = towerBuilder(x);
  21.     for (int i=0; i < x; i++)
  22.         std::cout << result[i] << std::endl;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement