【題解】UVA 10656 Maximum Sum (II)

【題目敘述】https://vjudge.net/problem/UVA-10656
【解題想法】Greedy

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

int n, a;

int main(){
    while (cin >> n){
        if (n == 0) break;
        bool flag = false;
        for (int i = 0; i < n; i++){
            cin >> a;
            if (a > 0){
                if (flag) cout << " ";
                else flag = true;
                cout << a;
            }
        }
        if (!flag) cout << 0;
        cout << "\n";
    }
}
分享本文 Share with friends