这个方法既节约了空间又节约了时间:

#include"iostream"
#include"queue"
#include"string.h"
#include"stdio.h"
#include"cmath"
using namespace std;
int  main()
{
    int i,j,s,t;
    queue<int>q;
    q.push(1);
    for(i=1;i<=10;i++)
    {
        s=0;q.push(0);
        for(j=0;j<i+1;j++)
        {
            t=q.front();
            q.pop();
            if(t)
            cout<<t<<' ';
            q.push(s+t);//输出上一行的同时将下一行进队列
            s=t;
        }
        cout<<endl;
    }
    return 0;
}
View Code

相关文章:

  • 2022-01-14
  • 2021-11-16
  • 2021-08-14
  • 2021-06-09
  • 2021-04-20
  • 2021-05-11
  • 2021-12-23
猜你喜欢
  • 2022-01-05
  • 2021-09-10
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
相关资源
相似解决方案