Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
2794 孙浚轩 打印菱形 C++ Accepted 0 MS 268 KB 504 2024-02-24 23:01:39

Tests(10/10):


Code:

#include<iostream> using namespace std; int main(){ int n; cin>>n; int f=(2*n-1)/2,l=(2*n-1)/2; bool d=0; for(int i=0;;){ for(int j=0;j<2*n-1;j++){ if(j>=f&&j<=l) cout<<"*"; else cout<<" "; } cout<<endl; if(i==n-1) d=1; if(d==0) i++,f--,l++; else{ i--,f++,l--; if(i<0) break; } } return 0; }