#include <cstdio> #include <vector> // https://cplusplus.com/reference/vector/vector/ using namespace std; enum { N = 10, W = N * 4 }; typedef vector<int> row; void print(int n, const row& r) { int w = n * 4; if (int left = (W - w) / 2) printf("%-*c", left, ' '); for (int i = 0; i < r.size(); i++) printf("%-4d", r[i]); puts(""); } int main() { row r(2, 1); // [1, 1] for x + for (int n = 2; n <= N; n++) { print(n, r); // (x + y) * (xx + 2xy + yy) = // xxx + 2xxy + xyy + 1 2 1 0 // xxy + 2xyy + yyy 0 1 2 1 const int m = r.size(); r.push_back(0); row t = r; t.insert(t.begin(), 0); for (int i = 0; i <= m; i++) r[i] += t[i]; } getchar(); return 0; } /* iterator insert (iterator position, const value_type& val); 应为r.insert(r.begin(), 0); r.insert(0, 0); VC6,Warning Level 3: 没警告没错误,一运行就崩 */
令x=y=1,可得2n等于?n个灯,从全亮到全灭,亮=1, 灭=0,有多少种组合?
标签:%-,int,vector,printf,杨辉三角,row From: https://www.cnblogs.com/funwithwords/p/17052109.html