#include <iostream>
#include <queue>
using namespace std;
int main()
{
queue<int> yh;
int n;
cout << "how many lines do you want to see?" << endl;
cin >> n;
int i = 1;
yh.push(0); yh.push(1); yh.push(0);
while (i <= n)
{
int j = 1;
while (j < i + 2)
{
int k1 = yh.front();
yh.pop();
if (k1 != 0)
cout << k1 << " ";
int k2 = yh.front();
yh.push(k1 + k2);
j++;
}
yh.push(0);
cout << endl;
i++;
}
system("pause");
return 0;
}
队列实现杨辉三角形
最新推荐文章于 2022-11-09 21:47:41 发布