当前位置:网站首页>PAT1027 Printing Hourglass
PAT1027 Printing Hourglass
2022-08-09 16:18:00 【Yellow duck 233】
#include <stdio.h>
#include <string.h>
int shalou(size_t size, char s)
{
int top = 0;
if(size == 0)
return 0;
for(int i = 3; i <= 10000; i += 2)
{
top += i;
if(top*2+1 > size)
{
top -= i;
size = top == 1 ? 1 : top * 2 + 1;
break;
}
}
char arr[1000][1000];
int cnt = 0, index = 0;
for(int i = 1; cnt < top + 1; i+=2)
{
cnt+=i;
for(int j = 0; j < i; j++)
arr[index][j] = s;
index++;
}
for(int i = index - 1; i >= 0; i --)
{
for(int j = 0; j < (strlen(arr[index - 1])-strlen(arr[i]))/2; j++)
printf(" ");
printf("%s\n", arr[i]);
}
for(int i = 1; i < index; i++)
{
for(int j = 0; j < (strlen(arr[index - 1])-strlen(arr[i]))/2; j++)
printf(" ");
printf("%s\n", arr[i]);
}
return size;
}
int main()
{
int n;
char c;
scanf("%d %c", &n, &c);
int la = n - shalou(n, c);
printf("%d\n", la);
return 0;
}

边栏推荐
猜你喜欢

How to create a new project with VS+Qt

redis从入门到精通

Mathematica 作图详解

写在光学之前--振动和波

内存泄露检测工具VLD(Visual Leak Detector)使用说明

OpenCV简介与搭建使用环境

Suddenly want to analyze the mortgage interest rate and interest calculation

6大论坛,30+技术干货议题,2022首届阿里巴巴开源开放周来了!

Inverted order at the beginning of the C language 】 【 string (type I like Beijing. Output Beijing. Like I)

redis6在centos7的安装
随机推荐
原子的核型结构及氢原子的波尔理论
How to achieve long-term benefits through the Tongdaxin quantitative trading interface?
常见编译问题
程序化交易规则对于整个交易系统有什么意义?
量化投资者是如何获取实时行情数据的呢?
数据库多表链接查询的方式
[ERR] 1273 - Unknown collation: ‘utf8mb4_0900_ai_ci‘
怎么才可以知道量化程序化交易是否有效?
NetCore 5.0连接MySql
SNR 信噪比
如何灵活运用量化交易接口的优势取长补短?
LNK1123:转换到COFF期间失败:文件无效或损坏
在量化交易过程中,散户可以这样做
It is deeply recognized that the compiler can cause differences in the compilation results
WebGL探索——抉择:实践方向(twgl.js、Filament、Claygl、BabylonJS、ThreeJS、LayaboxJS、SceneJS、ThinkJS、ThingJS)
ASP.Net Core实战——身份认证(JWT鉴权)
redis从入门到精通
MySql中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
Several important functions of singly linked list (including insertion, deletion, reversal, etc.)
Analysis: Which method is used to build a stock quantitative trading database?