当前位置:网站首页>【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
边栏推荐
- Markdown < a > tag new page open link
- NC basic usage 1
- The flinkcdc reports an error: but this is no longer available on the server
- Don't bother tensorflow learning notes (10-12) -- Constructing a simple neural network and its visualization
- DNS cloud school | quickly locate DNS resolution exceptions and keep these four DNS status codes in mind
- Cadence OrCAD capture batch change component packaging function introduction graphic tutorial and video demonstration
- Wave field Dao new species end up, how does usdd break the situation and stabilize the currency market?
- Mysql database - single table query (II)
- Mysql database - single table query (I)
- Mysql database - connection query
猜你喜欢
![[graph theory brush question-4] force deduction 778 Swimming in a rising pool](/img/e3/a8cd9fc7773843e9e8ee6a6eba123f.png)
[graph theory brush question-4] force deduction 778 Swimming in a rising pool

MySQL advanced lock - overview of MySQL locks and classification of MySQL locks: global lock (data backup), table level lock (table shared read lock, table exclusive write lock, metadata lock and inte

Linux64Bit下安装MySQL5.6-不能修改root密码

Don't bother tensorflow learning notes (10-12) -- Constructing a simple neural network and its visualization

Fundamentals of network communication (LAN, Wan, IP address, port number, protocol, encapsulation and distribution)

16MySQL之DCL 中 COMMIT和ROllBACK

Five minutes to show you what JWT is

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

JDBC tool class jdbcfiledateutil uploads files and date format conversion, including the latest, simplest and easiest way to upload single files and multiple files

Understanding various team patterns in scrum patterns
随机推荐
ArcGIS JS version military landmark drawing (dovetail arrow, pincer arrow, assembly area) fan and other custom graphics
Alicloud: could not connect to SMTP host: SMTP 163.com, port: 25
STM32基础知识
nc基础用法3
Mysql database - single table query (II)
go-zero框架数据库方面避坑指南
R语言使用econocharts包创建微观经济或宏观经济图、indifference函数可视化无差异曲线、自定义计算交叉点、自定义配置indifference函数的参数丰富可视化效果
LeetCode异或运算
R语言使用timeROC包计算存在竞争风险情况下的生存资料多时间AUC值、使用cox模型、并添加协变量、R语言使用timeROC包的plotAUCcurve函数可视化多时间生存资料的AUC曲线
[numerical prediction case] (3) LSTM time series electricity quantity prediction, with tensorflow complete code attached
The flinkcdc reports an error: but this is no longer available on the server
Building the tide, building the foundation and winning the future -- the successful holding of zdns Partner Conference
nc基础用法4
Design of warehouse management database system
Mysql database - basic operation of database and table (II)
The market share of the financial industry exceeds 50%, and zdns has built a solid foundation for the financial technology network
Vericrypt file hard disk encryption tutorial
Introduction to electron Tutorial 4 - switching application topics
Openharmony open source developer growth plan, looking for new open source forces that change the world!
selenium. common. exceptions. WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT