首页 > 其他 > 详细

PTA 打印沙漏

时间:2019-02-17 12:22:07      阅读:262      评论:0      收藏:0      [点我收藏+]

https://pintia.cn/problem-sets/17/problems/260

 

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int N;
    char sign;
    cin >> N >> sign;
    int count = 1;
    while (2 * count * count - 1 <= N)
    {
        count++;
    }
    count--;

    for (int i = 0; i < 2 * count - 1; i++)
    {
        for (int j = 0; j < count - 1 - abs(count - 1 - i); j++)
        {
            printf(" ");
        }
        for (int j = 0; j < 2 * abs(count - 1 - i) + 1; j++)
        {
            printf("%c", sign);
        }
        printf("\n");
    }
    printf("%d", N - (2 * count * count - 1));
    return 0;
}

 

PTA 打印沙漏

原文:https://www.cnblogs.com/ruoh3kou/p/10390434.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!