当前位置:网站首页>PAT1027 打印沙漏
PAT1027 打印沙漏
2022-08-09 14:53:00 【黄小鸭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;
}

边栏推荐
- 玩转云端 | 天翼云电脑的百变玩法
- 函数调用约定
- 生产者/消费者问题(线程信号)
- 注解与反射
- 相似图像的检测方法
- What are the implications of programmatic trading rules for the entire trading system?
- DSPE-PEG-Hydrazide, DSPE-PEG-HZ, Phospholipid-Polyethylene Glycol-Hydrazide MW: 1000
- [ERR] 1273 - Unknown collation: ‘utf8mb4_0900_ai_ci‘
- [MySql] implement multi-table query - one-to-one, one-to-many
- docke安装mysql以及主从搭建(并且指定数据生成路径)
猜你喜欢
随机推荐
软件工程基础知识--软件过程模型
Technology Sharing | How to Handle Header Cookies in Interface Automation Testing
What are the hot topics in quantitative programmatic trading?
函数调用约定
Mysql two engines comparison
[ERR] 1273 - Unknown collation: ‘utf8mb4_0900_ai_ci‘
What do professional quantitative traders think about quantitative trading?
股票程序化交易如何理解自己的交易系统?
docker安装seata(指定配置文件、数据库、容器数据卷等)
How to make your quantitative trading system have probabilistic advantages and positive return expectations?
经典面试题 之 JVM调优
突然想分析下房贷利率及利息计算
docke安装mysql以及主从搭建(并且指定数据生成路径)
【基础版】整数加减乘除计算器
英语议论文读写02 Engineering
What drives the development of quantitative trading interfaces?
卷积神经网络表征可视化研究综述(1)
MySql中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
[Basic version] Integer addition, subtraction, multiplication and division calculator
注释,标识符,数据类型









