当前位置:网站首页>[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
边栏推荐
- Handwritten Google's first generation distributed computing framework MapReduce
- R语言使用timeROC包计算存在竞争风险情况下的生存资料多时间AUC值、使用cox模型、并添加协变量、R语言使用timeROC包的plotAUCcurve函数可视化多时间生存资料的AUC曲线
- Click an EL checkbox to select all questions
- Implementation of mypromise
- How can matlab obtain the truncated image in trainingimagelabeler
- PIP installation package reports an error. Could not find a version that satisfies the requirement pymysql (from versions: none)
- SQL Server Connectors By Thread Pool | DTSQLServerTP 插件使用说明
- PostgreSQL basic functions
- 【PTA】L2-011 玩转二叉树
- 论文写作 19: 会议论文与期刊论文的区别
猜你喜欢
How to protect ECs from hacker attacks?
Servlet learning notes
Operation of numpy array
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
After route link navigation, the sub page does not display the navigation style problem
Click an EL checkbox to select all questions
Three. Based on ply format point cloud voxel model JS upload interface writing
Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
【PTA】整除光棍
[graph theory brush question-4] force deduction 778 Swimming in a rising pool
随机推荐
2022 - Data Warehouse - [time dimension table] - year, week and holiday
上海回應“面粉官網是非法網站”:疏於運維被“黑”,警方已立案
SIGIR'22 "Microsoft" CTR estimation: using context information to promote feature representation learning
微信中金财富高端专区安全吗,证券如何开户呢
DTMF dual tone multi frequency signal simulation demonstration system
Three. Based on ply format point cloud voxel model JS upload interface writing
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
【PTA】整除光棍
Commit and ROLLBACK in DCL of 16mysql
2022DASCTF Apr X FATE 防疫挑战赛 CRYPTO easy_real
go-zero框架数据库方面避坑指南
PCL点云处理之基于PCA的几何形状特征计算(五十二)
上海回应“面粉官网是非法网站”:疏于运维被“黑”,警方已立案
Investigate why close is required after sqlsession is used in mybatties
DTMF双音多频信号仿真演示系统
ArcGIS js api 4. X submergence analysis and water submergence analysis
Implementation of mypromise
Unity 模型整体更改材质
Identification of bolt points in aerial photography based on perception
Recognition of high-speed road signs by Matlab using alexnet