题解 | 卡牌游戏

卡牌游戏

https://www.nowcoder.com/practice/717961865ee54e7e8839c0b93b6ee597

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    if(n==1){
        cout<<"0\n";
        return 0;
    }
    long long x,sum=0,current=0;
    cin>>x;
    current=x;
    for(int i=2;i<=n;i++){
        cin>>x;
        current+=x;
        if(current>0)
        sum+=current;
    }
    cout<<sum<<'\n';
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

12-19 22:04
武汉大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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