思路分析:
输入N=2*(3+5+7+……+2*x-1)+1,求出x*x=(N+1)/2;按照格式输出
注意:最后一行要打印出剩下的符号数(为0也要打印),感觉有点坑
#include"stdio.h"
#include<math.h>
int main()
{int n, x = 0, ans,cnt;char s;scanf("%d %c", &n, &s);if (n == 0) {printf("0");return 0;}while (x*x <= (n + 1) / 2 ) {x++;}cnt = --x; //cnt=x,cnt即为满足要求的x;注意要x--ans = n - (2 * x * x - 1);for (int i =2*x-1; i >0; i--) {int j;if (i >= x) {j = 2 * (cnt--) - 1;}else { if (cnt == 0) cnt += 2;j = 2 * (cnt++) - 1;}for (int m =(2*x-j-1)/2; m > 0; m--)printf(" ");for (; j > 0; j--)printf("%c", s);printf("\n");}printf("%d", ans);return 0;
}