#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
queue<int> Q;
int temp;
void tringle(const int n)
{
    Q.push(1);
    for(int i=2;i<=n;i++)
    {
        Q.push(1);
        for(int j=1;j<=i-2;j++)
        {
            temp=Q.front();
            Q.pop();
            printf(" %d",temp);
            temp=temp+Q.front();
            Q.push(temp);
        }
        int x=Q.front();
        Q.pop();
        printf(" %d\n",x);
        Q.push(1);
    }
    while(!Q.empty())
    {
        temp=Q.front();
        Q.pop();
        printf(" %d",temp);
    }
}
int main()
{
    tringle(6);
    return 0;
}

用队列打印杨辉三角

相关文章:

  • 2021-05-21
  • 2021-12-09
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-29
  • 2021-09-22
相关资源
相似解决方案