当前位置:网站首页>【PTA】L1-002 打印沙漏
【PTA】L1-002 打印沙漏
2022-04-23 20:20:00 【也许会吧】
预备知识点
等差数列
通项和求和公式
原题链接
解题思路
运用等差数列计算行数
ac代码
#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));//上三角行数
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;
}
版权声明
本文为[也许会吧]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_55475680/article/details/124351462
边栏推荐
- R语言ggplot2可视化分面图(facet_wrap)、使用lineheight参数自定义设置分面图标签栏(灰色标签栏)的高度
- Mysql database and table building: the difference between utf8 and utf8mb4
- Rédaction de thèses 19: différences entre les thèses de conférence et les thèses périodiques
- Linux64Bit下安装MySQL5.6-不能修改root密码
- R语言使用econocharts包创建微观经济或宏观经济图、indifference函数可视化无差异曲线、自定义计算交叉点、自定义配置indifference函数的参数丰富可视化效果
- Solution to PowerDesigner's failure to connect to MySQL in x64 system
- selenium. common. exceptions. WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
- Wave field Dao new species end up, how does usdd break the situation and stabilize the currency market?
- Openharmony open source developer growth plan, looking for new open source forces that change the world!
- Numpy Index & slice & iteration
猜你喜欢
Es keyword sorting error reason = fielddata is disabled on text fields by default Set fielddata = true on keyword in order
[numerical prediction case] (3) LSTM time series electricity quantity prediction, with tensorflow complete code attached
Openharmony open source developer growth plan, looking for new open source forces that change the world!
[talkative cloud native] load balancing - the passenger flow of small restaurants has increased
Wave field Dao new species end up, how does usdd break the situation and stabilize the currency market?
Sqoop imports tinyint type fields to boolean type
BMP JPEG 图片转换为矢量图像 ContourTrace
Five minutes to show you what JWT is
WordPress plug-in: WP CHINA Yes solution to slow domestic access to the official website
程序设计语言基础(2)
随机推荐
JDBC tool class jdbcfiledateutil uploads files and date format conversion, including the latest, simplest and easiest way to upload single files and multiple files
Openharmony open source developer growth plan, looking for new open source forces that change the world!
nc基础用法
Don't bother tensorflow learning notes (10-12) -- Constructing a simple neural network and its visualization
Azkaban recompile, solve: could not connect to SMTP host: SMTP 163.com, port: 465 [January 10, 2022]
AQS learning
Commit and rollback in DCL of 16 MySQL
Leetcode XOR operation
本地调用feign接口报404
Mysql database backup scheme
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
ArcGIS JS version military landmark drawing (dovetail arrow, pincer arrow, assembly area) fan and other custom graphics
Cadence Orcad Capture CIS更换元器件之Link Database 功能介绍图文教程及视频演示
【2022】将3D目标检测看作序列预测-Point2Seq: Detecting 3D Objects as Sequences
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
Redis的安装(CentOS7命令行安装)
Mysql database - single table query (I)
Unity 模型整体更改材质
程序设计语言基础(2)
How does onlyoffice solve no route to host