当前位置:网站首页>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;
}
边栏推荐
- Detailed description of binary search tree
- JVM Part 1: memory and garbage collection part 6 -- runtime data area local method & local method stack
- B1025 reverse linked list*******
- Could not autowire. No beans of ‘userMapper‘ type found.
- Dialog data transfer
- How to sinicize the JMeter interface?
- OFDM 16 lecture 2-ofdm and the DFT
- 探寻通用奥特能平台安全、智能、性能的奥秘!
- [untitled] I is circularly accumulated under certain conditions. The condition is usually the length of the loop array. When it exceeds the length, the loop will stop. Because the object cannot judge
- The interface can automatically generate E and other asynchronous access or restart,
猜你喜欢

TypeScript 详解

数据库连接池&&Druid使用

Event

JVM Part 1: memory and garbage collection part 6 -- runtime data area local method & local method stack

pyside2____1.安装和案列

2021 OWASP top 6-10 collection

Laozi cloud and Fuxin Kunpeng achieved a major breakthrough in 3D ofd 3D format documents for the first time

Standard dialog qmessagebox

树莓派rtmp推流本地摄像头图像

实用小工具: Kotlin 代码片段
随机推荐
Could not autowire.No beans of ‘userMapper‘ type found.
JVM Part 1: memory and garbage collection part 8 - runtime data area - Method area
B1025 reverse linked list*******
2022 Zhengzhou light industry Freshmen's competition topic - I won't say if I'm killed
The provision of operation and maintenance manager is significantly affected, and, for example, it is like an eep command
求组合数(最强优化)
实用小工具: Kotlin 代码片段
File processing (IO)
Tcp server是如何一个端口处理多个客户端连接的(一对一还是一对多)
一、MySQL基础
JVM上篇:内存与垃圾回收篇三--运行时数据区-概述及线程
2、 MySQL advanced
Acceptance and neglect of events
微淼联合创始人孙延芳:以合规为第一要义,做财商教育“正规军”
探寻通用奥特能平台安全、智能、性能的奥秘!
Introduction to Web Framework
35. Scroll
Database design - relational data theory (ultra detailed)
Explore the mysteries of the security, intelligence and performance of the universal altek platform!
听过最自律的一句话: 那些我难以言表 不作声响