当前位置:网站首页>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;
}

边栏推荐
- JVM简学笔记
- .Net Core 技巧小结
- Welcome to use CSDN - markdown editor
- What are the hot topics in quantitative programmatic trading?
- Talking about Shallow Cloning and Deep Cloning of ArraryList
- What do professional quantitative traders think about quantitative trading?
- 单向链表几个比较重要的函数(包括插入、删除、反转等)
- [Mysql]--Transaction, transaction isolation level, dirty read, non-repeatable read, phantom read analysis
- What are the misunderstandings about the programmatic trading system interface?
- VS2010:出现devenv.sln解决方案保存对话框
猜你喜欢
随机推荐
内存泄露检测工具VLD(Visual Leak Detector)使用说明
How to create a new project with VS+Qt
双摄像头系列原理深度剖析【转载】
Left-handed and Right-handed Binary Sorted Trees
redis从入门到精通
For programming trading, focusing on forecast or on countermeasures?
股票程序化交易如何理解自己的交易系统?
简单记录下offsetof和container_of
Mathematica 作图详解
【小白必看】初始C语言(下)
用户如何正确去认识程序化交易?
What are the misunderstandings about the programmatic trading system interface?
.Net Core 技巧小结
常用类学习
分析:通过哪种方法来建立股票量化交易数据库?
Several important functional operations of general two-way circular list
如何保证电脑硬盘格式化后数据不能被恢复?
WebGL探索——抉择:实践方向(twgl.js、Filament、Claygl、BabylonJS、ThreeJS、LayaboxJS、SceneJS、ThinkJS、ThingJS)
Matlab修改Consolas字体
经典面试题 之 TCP 三次握手/ 四次挥手









