打印杨辉三角形

#include <iostream>
#include <string>
#include <queue>
using namespace std;

int main()
{
    queue<int> q;
    q.push(1);
    q.push(1);
    int n;
    cin>>n;
    int head=0,rear=0,sum=0;

    for(int i=1;i<=n;i++)
    {
        q.push(0);
        for(int j=1;j<=i+2;j++)
        {
            head=q.front();
            q.pop();
            sum=head+rear;
            q.push(sum);
            if(head)
                cout<<head<<" ";
            rear = head;
        }
        cout<<endl;

    }
    return 0;
}
原文地址:https://www.cnblogs.com/syzyaa/p/13812953.html