当前位置:网站首页>1. print hourglass
1. print hourglass
2022-06-28 11:46:00 【HBUcs2020】
#include<iostream>
using namespace std;
int main()
{
int n;
char c;
cin>>n;
getchar();
cin>>c;
// perhaps scanf("%d %c",&n,&c);
//1. Find the maximum number of layers
// If the number of layers is x, Then the top number is x
int neednum=1; // The number of symbols required to print the hourglass
int level=1; // The layer number
while(n/neednum)
{
level+=2;
neednum+=level*2;
}
// Pay attention to the order of the following two sentences
neednum-=level*2;
level-=2;
//2. Printout :① Print space ② Print symbols
for(int i=0;i<level/2+1;i++) //5->3
{
for(int a=i;a>0;a--) //0 1 2
{
printf(" ");
}
for(int b=2*(level/2+1-i)-1;b>0;b--)
{
printf("%c",c);
}
printf("\n");
}
for(int i=1;i<=level/2;i++)
{
for(int a=level/2-i;a>0;a--)
{
printf(" ");
}
for(int b=i*2+1;b>0;b--)
{
printf("%c",c);
}
printf("\n");
}
printf("%d",n-neednum);
return 0;
}边栏推荐
- Xshell and xftp tutorial
- What method is required for word, PDF and txt files to realize full-text content retrieval?
- Machine learning project captcha based on verification code recognition_ Trainer operation practice
- This Exception was thrown from a job compiled with Burst, which has limited exception support. 报错
- js中的class类模式及语法 2021.11.10
- Join hands with cigent: group alliance introduces advanced network security protection features for SSD master firmware
- day31 js笔记 DOM下 2021.09.26
- Making and using of dynamic library (shared library)
- What is the main chain system?
- Thesis reading (59):keyword based diverse image retrieval with variable multiple instance graph
猜你喜欢

Industry analysis - quick intercom, building intercom

智联招聘基于 Nebula Graph 的推荐实践分享

功能真花哨,价格真便宜!长安全新SUV真实力到底怎样?

day29 js笔记 2021.09.23

Array method in JS 2021.09.18

Redis6 1: what problems can be solved by the introduction of NoSQL and redis?

Oracle date format exception: invalid number

Fruit FL studio/cubase/studio one music host software comparison

String & heap & method area

Day39 prototype chain and page Fireworks Effect 2021.10.13
随机推荐
NFT卡牌链游系统开发dapp搭建技术详情
Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community
Apache2 configuration denies access to the directory, but can access the settings of the files inside
ThreadLocal的简单理解
Which programming language will attract excellent talents?
人人都可以参与开源!龙蜥社区最不容错过的开发者活动来了
Contract quantification system development (construction explanation) - contract quantification system development (source code analysis and ready-made cases)
网页提示此站点不安全解决方案
Array method in JS 2021.09.18
js中的class类模式及语法 2021.11.10
Convert the file URL in the browser to a file stream
Lihongyi, machine learning 7 Conclusion
NFT card chain game system development DAPP construction technical details
day37 js笔记 运动函数 2021.10.11
String & heap & method area
day33 js笔记 事件(下)2021.09.28
[no title] the virtual machine vmnet0 cannot be found and an error is reported: there is no un bridged host network adapter
一套十万级TPS的IM综合消息系统的架构实践与思考
Analyze whether there is duplicate data in the list and repeat it several times
Intranet penetration in the working group environment: some basic methods