1027 打印沙漏(20 分)

行数计算
#include
#include
#include
using namespace std;
int N, n;
char c;
int main()
{
    scanf("%d %c", &N, &c);
    n = sqrt((N + 1) / 2);
    for (int i = n; i>0;i--)
    {
        for (int k = 0; k < n - i; k++)printf(" ");
        for (int j = 0; j < 2 * i - 1; j++)printf("%c", c);
        printf("\n");
    }
    for (int i = 2; i <= n; i++)
    {
        for (int k = 0; k < n - i; k++)printf(" ");
        for (int j = 0; j < 2 * i - 1; j++)printf("%c", c);
        printf("\n");
    }
    printf("%d", N - (2 * n*n - 1));
    return 0;
}

你可能感兴趣的:(1027 打印沙漏(20 分))