当前位置:网站首页>[PTA] l1-002 printing hourglass
[PTA] l1-002 printing hourglass
2022-04-23 20:23:00 【Maybe】
Prepare knowledge points
A sequence of equal differences
General term sum formula
Original link
Their thinking
Calculate the number of rows by using the sequence of equal differences
ac Code
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int main() {
int t;
char a;
cin >> t;
getchar();
cin >> a;
int n = (t + 1) / 2;
n = int(sqrt(n));// Number of upper triangular rows
t = t - n * n * 2 + 1;
for(int i = 0; i < n; i++){
for(int j = 0; j < i; j++)
cout << ' ';
for(int j = 0; j < 2 * (n - i) - 1; j++)
cout << a;
cout << endl;
}
for(int i = n - 2; i >= 0; i--){
for(int j = i; j > 0; j--)
cout << ' ';
for(int j = 0; j < 2 * (n - i) - 1; j++)
cout << a;
cout << endl;
}
cout << t;
return 0;
}
版权声明
本文为[Maybe]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204232020000365.html
边栏推荐
- How does onlyoffice solve no route to host
- NC basic usage
- LeetCode动态规划训练营(1~5天)
- [graph theory brush question-4] force deduction 778 Swimming in a rising pool
- 论文写作 19: 会议论文与期刊论文的区别
- 中金财富公司怎么样,开户安全吗
- Building the tide, building the foundation and winning the future -- the successful holding of zdns Partner Conference
- Redis installation (centos7 command line installation)
- Matlab analytic hierarchy process to quickly calculate the weight
- The R language uses the timeroc package to calculate the multi time AUC value of survival data without competitive risk, and uses the confint function to calculate the confidence interval value of mul
猜你喜欢
LeetCode动态规划训练营(1~5天)
Linux64Bit下安装MySQL5.6-不能修改root密码
Commit and ROLLBACK in DCL of 16mysql
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
WordPress plug-in: WP CHINA Yes solution to slow domestic access to the official website
Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
The ODB model calculates the data and outputs it to excel
16MySQL之DCL 中 COMMIT和ROllBACK
On BIM data redundancy theory
Sqoop imports tinyint type fields to boolean type
随机推荐
Notes of Tang Shu's grammar class in postgraduate entrance examination English
Matlab analytic hierarchy process to quickly calculate the weight
Customize timeline component styles
PCA based geometric feature calculation of PCL point cloud processing (52)
Commit and ROLLBACK in DCL of 16mysql
Experience of mathematical modeling in 18 year research competition
Alicloud: could not connect to SMTP host: SMTP 163.com, port: 25
RT-1052学习笔记 - GPIO架构分析
Cadence OrCAD capture batch change component packaging function introduction graphic tutorial and video demonstration
How does onlyoffice solve no route to host
Leetcode dynamic planning training camp (1-5 days)
【PTA】L1-002 打印沙漏
redis 分布式锁
[graph theory brush question-4] force deduction 778 Swimming in a rising pool
NC basic usage
Change the material of unity model as a whole
Solution to PowerDesigner's failure to connect to MySQL in x64 system
NC basic usage 3
LeetCode动态规划训练营(1~5天)
Latest investigation and progress of building intelligence based on sati