0% found this document useful (0 votes)
3 views2 pages

C++ Pyramid Pattern Generator

The document contains a C++ program that generates a pyramid-like structure based on user input for the number of levels, size, and a specific position to modify. It creates a 2D vector to represent the pyramid, marks a specific area with a different value, and then simulates falling blocks within the pyramid. Finally, it outputs the modified pyramid structure using '#' for filled spaces and spaces for empty ones.

Uploaded by

ten.pattaradanai
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

C++ Pyramid Pattern Generator

The document contains a C++ program that generates a pyramid-like structure based on user input for the number of levels, size, and a specific position to modify. It creates a 2D vector to represent the pyramid, marks a specific area with a different value, and then simulates falling blocks within the pyramid. Finally, it outputs the modified pyramid structure using '#' for filled spaces and spaces for empty ones.

Uploaded by

ten.pattaradanai
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <iostream>

#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

int main() {
int num,n=0,direct,size,row=0,collum=0;
cin >> num >> size >> direct;
for (int i = 0; i < num; i++) {
n += 2;
}
n -= 1;
vector<vector<int>> v(num, vector<int>(n, 0));
int space = num-1,story=1;
for (int i = 0; i < num; i++) {
for (int j = 0; j < n; j++) {
if (j >= space && j <= space + story - 1) {
v[i][j] = 1;
}
else {
v[i][j] = 0;
}
}
space--;
story+=2;
}

int count = 0;
for (int i = 0; i < num; i++) {
for (int j = 0; j < n; j++) {
if (v[i][j] == 1) {
count++;
if (count == direct) {
row = i;
collum = j;
}
}
}
}

for (int i = -(size/2); i < -(size/2)+size; i++) {


for (int j = -(size/2) ; j < -(size/2)+size; j++) {
if (row+i >= 0 && row+i < [Link]() && collum+j >= 0 && collum+j <
v[0].size())
v[row+i][collum+j] = 3;
}
}

for (int j = 0; j < n; j++) {


int one=0;
vector <int> fall;
for (int i = 0; i < num; i++) {
if (v[i][j] == 1) {
one++;
fall.push_back(i);
}
}
for (int i = num-1; i >= 0; i--) {
if (v[i][j] == 3 && one != 0) {
v[i][j] = 1;
v[fall[0]][j] = 0;
one--;
[Link]([Link]());
if (one == 0) {
break;
}
}
}
cout << endl;
}

for (int i = 0; i < num; i++) {


for (int j = 0; j < n; j++) {
if (v[i][j] == 1) {
cout << '#';
}
else {
cout << " ";
}
}
cout << endl;
}
}

You might also like