题解 | #金字塔#

金字塔

https://ac.nowcoder.com/acm/problem/22203

如果测试错了但AC了,题目是说多个测试数据,因此记得要有while(cin>>n)能输入多个测试数据,这样测试才不会出错。

using namespace std;
#define int long long
#define endl '\n'
signed main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n;
    while(cin>>n){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n-i;j++){
            cout<<" ";
        }
        for(int z=1;z<=2*i-1;z++){
            cout<<"*";
        }
        cout<<endl;
    }
    }
    return 0;
}
全部评论

相关推荐

2025-12-17 17:15
华东师范大学 运营
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务