当前位置:网站首页>[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
边栏推荐
- An error is reported when sqoop imports data from Mysql to HDFS: sqlexception in nextkeyvalue
- Is the wechat CICC wealth high-end zone safe? How to open an account for securities
- 上海回应“面粉官网是非法网站”:疏于运维被“黑”,警方已立案
- WordPress插件:WP-China-Yes解决国内访问官网慢的方法
- How about CICC fortune? Is it safe to open an account
- Experience of mathematical modeling in 18 year research competition
- Unity 模型整体更改材质
- Development of Matlab GUI bridge auxiliary Designer (functional introduction)
- Sqoop imports data from Mysql to HDFS using lzop compression format and reports NullPointerException
- [latex] 5 how to quickly write out the latex formula corresponding to the formula
猜你喜欢

Browser - learning notes

Zdns was invited to attend the annual conference of Tencent cloud basic resources and share the 2020 domain name industry development report

堡垒机、跳板机JumpServer的搭建,以及使用,图文详细

SQL Server connectors by thread pool 𞓜 instructions for dtsqlservertp plug-in

上海回應“面粉官網是非法網站”:疏於運維被“黑”,警方已立案

Identification of bolt points in aerial photography based on perception

A useless confession artifact
Handwritten Google's first generation distributed computing framework MapReduce

【PTA】L1-002 打印沙漏

How to protect ECs from hacker attacks?
随机推荐
How to do product innovation—— Exploration of product innovation methodology I
上海回應“面粉官網是非法網站”:疏於運維被“黑”,警方已立案
Use the rolling division method to find the maximum common divisor of two numbers
PIP installation package reports an error. Could not find a version that satisfies the requirement pymysql (from versions: none)
R language uses the preprocess function of caret package for data preprocessing: BoxCox transform all data columns (convert non normal distribution data columns to normal distribution data and can not
Matlab analytic hierarchy process to quickly calculate the weight
An error is reported when sqoop imports data from Mysql to HDFS: sqlexception in nextkeyvalue
Numpy mathematical function & logical function
如何做产品创新?——产品创新方法论探索一
Redis installation (centos7 command line installation)
Don't bother tensorflow learning notes (10-12) -- Constructing a simple neural network and its visualization
ABAQUS script email auto notification
Development of Matlab GUI bridge auxiliary Designer (functional introduction)
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
star
Remote code execution in Win 11 using wpad / PAC and JScript 1
Redis的安装(CentOS7命令行安装)
Es keyword sorting error reason = fielddata is disabled on text fields by default Set fielddata = true on keyword in order
Zdns was invited to attend the annual conference of Tencent cloud basic resources and share the 2020 domain name industry development report
Experience of mathematical modeling in 18 year research competition