当前位置:网站首页>B1027 print hourglass
B1027 print hourglass
2022-07-27 05:20:00 【Ye Chen】
1027 Print hourglass (20 branch )
This question requires you to write a program to print the given symbol into the shape of an hourglass . For example, given 17 individual “*”, It is required to print in the following format
*****
***
*
***
*****
So-called “ Hourglass shape ”, Refers to the output of odd symbols per line ; Align symbol centers ; Number difference between two adjacent lines of symbols 2; The number of symbols decreases from large to small to 1, Increase from small to large ; Equal number of first and last symbols .
Given arbitrary N Symbols , It doesn't have to be an hourglass . Require the printed hourglass to use as many symbols as possible .
Input format :
Type in on a line to give 1 A positive integer N(≤1000) And a symbol , Space between
Output format :
First print out the largest hourglass shape made up of the given symbols , Finally, output the number of unused symbols in one line .
sample input
19 *
sample output
*****
***
*
***
*****
2
Topic analysis :
- Find the mathematical law, namely the number of inverted triangle lines k Satisfy 2kk-1 Equal to the number of points in the graph
- adopt k Value binding cycle for printing
The code is as follows :
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
char a;
cin>>n>>a;
int k=1;
while(k*k*2-1<=n){
k++;
}
k--;
for(int i=k;i>0;i--){
for(int m=0;m<k-i;m++){
cout<<" ";
}
for(int j=0;j<2*i-1;j++){
cout<<a;
}
cout<<endl;
}
for(int i=1;i<k;i++){
for(int m=0;m<k-i-1;m++){
cout<<" ";
}
for(int j=0;j<2*i+1;j++){
cout<<a;
}
cout<<endl;
}
int x=n-k*k*2+1;
(x)?printf("%d",x):printf("0");
return 0;
}
边栏推荐
- Standard dialog qmessagebox
- 知识点总结(一)
- Differences among left join, inner join and right join
- Database connection pool & Druid usage
- The project connects with Alipay payment, and the intranet penetration realizes the monitoring of asynchronous callback notification of successful payment of Alipay
- 求组合数(最强优化)
- TypeScript 详解
- Raspberry pie RTMP streaming local camera image
- Bean的生命周期&&依赖注入*依赖自动装配
- JVM上篇:内存与垃圾回收篇--运行时数据区四-程序计数器
猜你喜欢

Installation and template setting of integrated development environment pychar

Svn usage details

支付流程如何测试?

How to sinicize the JMeter interface?

素数筛选(埃氏筛法,区间筛法,欧拉筛法)
![[optical flow] - data format analysis, flowwarp visualization](/img/7d/2fefc32813ec0c93115e4b290b0944.png)
[optical flow] - data format analysis, flowwarp visualization

Translation of robot and precise vehicle localization based on multi sensor fusion in diverse city scenes

2021 OWASP top 4: unsafe design

JVM上篇:内存与垃圾回收篇二--类加载子系统

Dialog introduction
随机推荐
SQL数据库→约束→设计→多表查询→事务
idea远程调试debug
JVM Part 1: memory and garbage collection part 5 -- runtime data area virtual machine stack
Use of file i/o in C
The project connects with Alipay payment, and the intranet penetration realizes the monitoring of asynchronous callback notification of successful payment of Alipay
使用Druid连接池创建DataSource(数据源)
Translation of robot and precise vehicle localization based on multi sensor fusion in diverse city scenes
JVM上篇:内存与垃圾回收篇三--运行时数据区-概述及线程
Event Summary - common summary
Acticiti中startProcessInstanceByKey方法在variable表中的如何存储
B1031 查验身份证
JVM上篇:内存与垃圾回收篇二--类加载子系统
B1025 reverse linked list*******
ssm框架整合
B1021 个位数统计
Dialog data transfer
Complete Binary Tree
来自“飞人”乔丹的启示!奥尼尔开启的另一个“赛场”
34. 分析flexible.js
The interface can automatically generate E and other asynchronous access or restart,