当前位置:网站首页>[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
边栏推荐
- Numpy Index & slice & iteration
- Intersection calculation of straight line and plane in PCL point cloud processing (53)
- Monte Carlo py solves the area problem! (save pupils Series)
- Sqoop imports data from Mysql to HDFS using lzop compression format and reports NullPointerException
- WordPress plug-in: WP CHINA Yes solution to slow domestic access to the official website
- How to protect ECs from hacker attacks?
- How to do product innovation—— Exploration of product innovation methodology I
- Cadence Orcad Capture CIS更换元器件之Link Database 功能介绍图文教程及视频演示
- NC basic usage 3
- Latest investigation and progress of building intelligence based on sati
猜你喜欢
Tensorflow 2 basic operation dictionary
Modeling based on catiav6
WordPress plug-in: WP CHINA Yes solution to slow domestic access to the official website
Scripy tutorial - (2) write a simple crawler
【栈和队列专题】—— 滑动窗口
DNS cloud school | analysis of hidden tunnel attacks in the hidden corner of DNS
Installation and use of NVM
SIGIR'22 "Microsoft" CTR estimation: using context information to promote feature representation learning
Shanghai responded that "flour official website is an illegal website": neglect of operation and maintenance has been "hacked", and the police have filed a case
Recommend an open source free drawing software draw IO exportable vector graph
随机推荐
R语言ggplot2可视化:ggplot2可视化散点图并使用geom_mark_ellipse函数在数据簇或数据分组的数据点周围添加椭圆进行注释
The flinkcdc reports an error: but this is no longer available on the server
Shanghai responded that "flour official website is an illegal website": neglect of operation and maintenance has been "hacked", and the police have filed a case
Still using listview? Use animatedlist to make list elements move
中金财富公司怎么样,开户安全吗
R language uses econocrats package to create microeconomic or macroeconomic map, visualize indifference function indifference curve, customize calculation intersection, and customize the parameters of
R语言survival包coxph函数构建cox回归模型、ggrisk包ggrisk函数和two_scatter函数可视化Cox回归的风险评分图、解读风险评分图、基于LIRI数据集(基因数据集)
Redis installation (centos7 command line installation)
selenium. common. exceptions. WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
Customize timeline component styles
Why does ES6 need to introduce map when JS already has object type
BMP JPEG 图片转换为矢量图像 ContourTrace
WordPress插件:WP-China-Yes解决国内访问官网慢的方法
JDBC tool class jdbcfiledateutil uploads files and date format conversion, including the latest, simplest and easiest way to upload single files and multiple files
Cadence OrCAD capture batch change component packaging function introduction graphic tutorial and video demonstration
Leetcode dynamic planning training camp (1-5 days)
Recommend an open source free drawing software draw IO exportable vector graph
Remote code execution in Win 11 using wpad / PAC and JScript
Redis distributed lock
A useless confession artifact