A1048|输出实心菱形 解题
2026-08-03 20:35:53
发布于:江苏
26阅读
0回复
0点赞
这道题我没有用上下割🔪成两份的方法,我是先输出中间的那条线的上面⬆️然后输出中间哪条线🀄最后输出底下的⬇️。
完整代码:
#include<iostream>
using namespace std;
int main(){
short n;//short节省空间
char c;
ios::sync_with_stdio(false); //度|出|加
cin.tie(nullptr);// |入|快
cout.tie(nullptr);// |速|输
cin >> n >> c;
for(short i = 1; i <= n - 1; i++){
for(short j = 1; j <= n - i; j++) cout << ' ';
for(short j = 1; j <= i * 2 - 1; j++) cout << c;
cout << '\n';
}
for(int i = 1; i <= n * 2 - 1; i++) cout << c;
cout << '\n';
for(short i = 1; i <= n; i++){
for(short j = 1; j <= i; j++) cout << ' ';
for(short j = 1; j <= n * 2 - 1 - i * 2; j++) cout << c;
cout << '\n';
}
return 0;
}
这里空空如也







有帮助,赞一个