zoukankan      html  css  js  c++  java
  • 用队列打印杨辉三角

    #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
    ",x);
            Q.push(1);
        }
        while(!Q.empty())
        {
            temp=Q.front();
            Q.pop();
            printf(" %d",temp);
        }
    }
    int main()
    {
        tringle(6);
        return 0;
    }

  • 相关阅读:
    HDU 1429
    HDU 1622
    HDU 3335
    HDU 4160
    HDU 1350
    HDU 5086
    HDU 1300
    HDU 3047
    HDU 3038
    HDU 5100
  • 原文地址:https://www.cnblogs.com/jianfengyun/p/3885122.html
Copyright © 2011-2022 走看看