public class ss {
public void methed(int n){
if(n==1) System.out.print("1");
else if(n==2) System.out.print("1"+" "+"1");
else{
int[] a=new int[n+1];
a[0]=1;a[1]=1;a[2]=2;
int front=0,rear=3;
while(front!=rear){
if(a[front]==1&&a[(front+1)%(n+1)]==1){
front=(front+1)%(n+1);
a[rear]=1;a[(rear+1)%(n+1)]=1;
rear=(rear+2)%(n+1);
}
else{
a[rear]=a[front]+a[(front+1)%(n+1)];
front=(front+1)%(n+1);
rear=(rear+1)%(n+1);
}
}
//front=(front+1)%(n+1);
for(int i=1;i<=n;i++){
System.out.print(a[front]+" ");
front=(front+1)%(n+1);
}
}
}
public void methed1(int p){
for(int i=1;i<=p;i++){
for(int j=1;j<=(p-i);j++) System.out.print(" ");
methed(i);
System.out.println("");
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ss a=new ss();
a.methed1(10);
}
}
输出结果:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1