# 等腰三角形 本题目要求你在控制台输出一个由数字组成的等腰三角形。具体的步骤是: 先用1,2,3,…的自然数拼一个足够长的串 用这个串填充三角形的三条边。从上方顶点开始,逆时针填充。 比如,当三角形高度是8时: ![](https://img-blog.csdnimg.cn/20190203174943179.png) 输入,一个正整数n(3> n) { for (int i = 1; i < n; i++) { for (int j = 1; j <= n - i; j++) { cout << "."; } cout << s[i - 1]; if (i != 1) { for (int j = 1; j < i - 1; j++) { cout << "."; } cout << s[4 * (n - 1) + 1 - i]; } cout << endl; } for (int i = 0; i < 2 * (n - 1) + 1; i++) { cout << s[n - 1 + i]; } cout << endl; } return 0; } ``` ## 选项 ### A ```c int main() { int n; scanf("%d", &n); int s = 0; int q = 0, w = 0, count = 1; int arr[300][600]; int p = n - 1, r = n; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < r; j++) { if (j == p) { if (s == 2) { s = 1; arr[i][j] = q + '0'; } else if (s == 1) { s = 0; arr[i][j] = w + '0'; } else { arr[i][j] = count + '0'; count++; if (count == 10) { count = 0; w++; if (w == 10) { w = 0; q++; } } if (w != 0) { s = 1; } if (q != 0) { s = 2; } } } else { arr[i][j] = '.'; } } p--; r++; } for (int j = 0; j < r; j++) { if (s == 2) { s = 1; arr[n - 1][j] = q + '0'; } else if (s == 1) { s = 0; arr[n - 1][j] = w + '0'; } else { arr[n - 1][j] = count + '0'; count++; if (count == 10) { count = 0; w++; if (w == 10) { w = 0; q++; } } if (w != 0) { s = 1; } if (q != 0) { s = 2; } } } r--; for (int i = n - 2; i > 0; i--) { r--; if (s == 2) { s = 1; arr[i][r] = q + '0'; } else if (s == 1) { s = 0; arr[i][r] = w + '0'; } else { arr[i][r] = count + '0'; count++; if (count == 10) { count = 0; w++; if (w == 10) { w = 0; q++; } } if (w != 0) { s = 1; } if (q != 0) { s = 2; } } } r = n; for (int i = 0; i < n; i++) { for (int j = 0; j < r; j++) { printf("%c", arr[i][j]); } printf("\n"); r++; } return 0; } ``` ### B ```c int a[3005], n; char m[1300][1300]; void init() { int cnt = 1, p = 1; while (1) { if (cnt >= 3000) break; if (p < 10) a[cnt++] = p; else if (p < 100 && p >= 10) { a[cnt++] = p / 10; a[cnt++] = p % 10; } else if (p >= 100 && p < 1000) { a[cnt++] = p / 100; a[cnt++] = p / 10 % 10; a[cnt++] = p % 10; } else if (p >= 1000 && p < 9999) { a[cnt++] = p / 1000; a[cnt++] = p / 100 % 10; a[cnt++] = p / 10 % 10; a[cnt++] = p % 10; } p++; } } int main() { init(); cin >> n; int cnt = 1; for (int i = 1; i <= n - 1; i++) { for (int j = n; j >= 1; j--) if (i + j == n + 1) m[i][j] = a[cnt++] + '0'; else m[i][j] = '.'; } for (int i = 1; i <= n * 2 - 1; i++) m[n][i] = a[cnt++] + '0'; for (int i = n - 1; i >= 2; i--) { for (int j = 2 * n - 2; j >= n; j--) { if (j - i == n - 1) m[i][j] = a[cnt++] + '0'; else m[i][j] = '.'; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n + i - 1; j++) { cout << m[i][j]; } cout << endl; } return 0; } ``` ### C ```c string str; stringstream ss; int main() { int n; cin >> n; int x = 2 * n - 1; for (int i = 1; i <= 1500; i++) { string str1; ss << i; ss >> str1; str += str1; ss.clear(); } int length = 4 * n - 4; for (int i = 1; i <= n; i++) { if (i != n && i != 1) { for (int j = 1; j <= n + i - 1; j++) { if (j == n - i + 1) { cout << str[i - 1]; } else if (j == 2 * n - (n - i + 1)) { cout << str[4 * n - 4 - (i - 1)] << endl; } else { cout << '.'; } } } else if (i == 1) { for (int x = 1; x <= n; x++) { if (x == n) { cout << '1' << endl; } else { cout << '.'; } } } else { for (int m = 1; m <= 2 * n - 1; m++) { cout << str[n + (m - 2)]; } } } return 0; } ```