当前位置:网站首页>【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
边栏推荐
- Still using listview? Use animatedlist to make list elements move
- WordPress插件:WP-China-Yes解决国内访问官网慢的方法
- Local call feign interface message 404
- Introduction to electron Tutorial 4 - switching application topics
- Mysql database - single table query (III)
- An error is reported in the initialization metadata of the dolphin scheduler -- it turns out that there is a special symbol in the password. "$“
- Mysql database - single table query (I)
- Mysql database and table building: the difference between utf8 and utf8mb4
- After route link navigation, the sub page does not display the navigation style problem
- PIP installation package reports an error. Could not find a version that satisfies the requirement pymysql (from versions: none)
猜你喜欢
go-zero框架数据库方面避坑指南
Numpy mathematical function & logical function
selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
[talkative cloud native] load balancing - the passenger flow of small restaurants has increased
STM32基础知识
STM32 Basics
Browser - learning notes
【目标跟踪】基于帧差法结合卡尔曼滤波实现行人姿态识别附matlab代码
Commit and rollback in DCL of 16 MySQL
Operation of numpy array
随机推荐
Remote code execution in Win 11 using wpad / PAC and JScript 1
Redis distributed lock
LeetCode异或运算
Is the wechat CICC wealth high-end zone safe? How to open an account for securities
本地调用feign接口报404
Leetcode XOR operation
Recommend an open source free drawing software draw IO exportable vector graph
Cadence Orcad Capture 批量更改元件封装功能介绍图文教程及视频演示
CVPR 2022 | QueryDet:使用级联稀疏query加速高分辨率下的小目标检测
Cadence OrCAD capture batch change component packaging function introduction graphic tutorial and video demonstration
Numpy - creation of data type and array
CVPR 2022 | querydet: use cascaded sparse query to accelerate small target detection under high resolution
The flinkcdc reports an error: but this is no longer available on the server
JDBC tool class jdbcconutil gets the connection to the database
ArcGIS js api 4. X submergence analysis and water submergence analysis
redis 分布式锁
16MySQL之DCL 中 COMMIT和ROllBACK
Design of warehouse management database system
[2022] regard 3D target detection as sequence prediction - point2seq: detecting 3D objects as sequences
How about CICC fortune? Is it safe to open an account