모래시계 인쇄 (20)

/* 00-  1.     (20) http://www.patest.cn/contests/mooc-ds/00-%E8%87%AA%E6%B5%8B1 */
#include <cstdio> 
#include <sstream> 
#include <cstring> 
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <cmath>

using namespace std;

#define N 100001


int main()
{
  //freopen("in", "r", stdin);
  int n;
  char c;
  while (scanf("%d %c", &n, &c) != EOF)
  {
    double d = (n + 1) *1.0 / 2;
    int cengshu = (int)(floor(sqrt(d)));
    int tn = 2 * cengshu * cengshu - 1;
    int left = n - tn;

    int i, j;
    for (i = 0; i < cengshu; i++)
    {
      for (j = 0; j < i; j++)
      {
        printf(" ");
      }
      for (j = 0; j < 2 * (cengshu - i) - 1; j++)
      {
        printf("%c", c);
      }
      printf("
"
); } for (i = 1; i < cengshu; i++) { for (j = 0; j < cengshu -1-i; j++) { printf(" "); } for (j = 0; j < (2 * i + 1); j++) { printf("%c", c); } printf("
"
); } printf("%d
"
, left); } return 0; }

좋은 웹페이지 즐겨찾기