#include <iostream> using namespace std; int sak(int z) { return 1 + 4 * z + 2 * z * z; } int main() { int x; char a; cin >> x >> a; //cout << x << a << endl; int n = 0; //cout << sak(n + 1) << endl; while(!((x >= sak(n)) && (x < sak(n + 1)))) { n++; //cout << n << endl; } //cout << n; int k = n; int r = 0; for (; k != 0; k--,r++) { int s = 2 * k + 1; for (int i = 0; i < r; i++) { cout << " "; } for (int j = 0; j < s; j++) { cout << a; } cout << endl; } for (int i = 0; i < r; i++) { cout << " "; } cout << a << endl; k++; r--; for (; k != n + 1; r--, k++) { int s = 2 * k + 1; for (int i = 0; i < r; i++) { cout << " "; } for (int j = 0; j < s; j++) { cout << a; } cout << endl; } cout << x - sak(n); system("pause"); return 0; }
原文地址:https://www.cnblogs.com/huaye37/p/9699454.html
时间: 2024-10-24 13:42:33