CTK18 三角形数列
#include <bits/stdc++.h> using namespace std; int f(int x){ int ant = 0; while(x){ x /= 10; ant++; } return ant; } int main() { int n; cin>>n; int a[n+5][n+5]; for(int i = n;i>=1;i--){ for(int j = 1;j<=i;j++){ if(i==n){ a[i][j] = j; }else{ a[i][j] = a[i+1][j]+a[i+1][j+1]; } } } for(int i = 1;i<=n;i++){ for(int j = 1;j<=i;j++){ if(j==1){ cout<<setw((n-i)*4+f(a[i][j]))<<right<<a[i][j]; }else{ cout<<setw(8-f(a[i][j-1])+f(a[i][j]))<<a[i][j]; } } cout<<endl; } return 0; }