当前位置:网站首页>【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 language ggplot2 visual facet_wrap, and use the lineheight parameter to customize the height of the facet icon tab (gray label bar)
- STM32 Basics
- Solution to PowerDesigner's failure to connect to MySQL in x64 system
- How about CICC fortune? Is it safe to open an account
- Design of warehouse management database system
- NC basic usage 1
- Numpy mathematical function & logical function
- Numpy - creation of data type and array
- aqs的学习
- NC basic usage
猜你喜欢
LeetCode异或运算
Some basic configurations in interlij idea
【目标跟踪】基于帧差法结合卡尔曼滤波实现行人姿态识别附matlab代码
Livego + ffmpeg + RTMP + flvjs to realize live video
[target tracking] pedestrian attitude recognition based on frame difference method combined with Kalman filter, with matlab code
STM32 Basics
aqs的学习
CVPR 2022 | QueryDet:使用级联稀疏query加速高分辨率下的小目标检测
Mysql database backup scheme
LeetCode动态规划训练营(1~5天)
随机推荐
使用 WPAD/PAC 和 JScript在win11中进行远程代码执行
[numerical prediction case] (3) LSTM time series electricity quantity prediction, with tensorflow complete code attached
How to do product innovation—— Exploration of product innovation methodology I
How about CICC fortune? Is it safe to open an account
Remote code execution in Win 11 using wpad / PAC and JScript 1
Redis的安装(CentOS7命令行安装)
Database query - course selection system
PostgreSQL basic functions
SIGIR'22「微软」CTR估计:利用上下文信息促进特征表征学习
如何做产品创新?——产品创新方法论探索一
Why does ES6 need to introduce map when JS already has object type
Design of warehouse management database system
[2022] regard 3D target detection as sequence prediction - point2seq: detecting 3D objects as sequences
LeetCode动态规划训练营(1~5天)
Azkaban recompile, solve: could not connect to SMTP host: SMTP 163.com, port: 465 [January 10, 2022]
Remote code execution in Win 11 using wpad / PAC and JScript
PCA based geometric feature calculation of PCL point cloud processing (52)
PIP installation package reports an error. Could not find a version that satisfies the requirement pymysql (from versions: none)
ArcGIS JS version military landmark drawing (dovetail arrow, pincer arrow, assembly area) fan and other custom graphics
R language uses econocrats package to create microeconomic or macroeconomic map, visualize indifference function indifference curve, customize calculation intersection, and customize the parameters of