【題解】Codeforces 1300A. Non-zero

【題目敘述】http://codeforces.com/contest/1300/problem/A

#include <iostream>
using namespace std;
 
int t, n, a, s, cnt;
 
int main() {
    cin >> t;
    while (t--){
        cin >> n;
        cnt = 0;
        s = 0;
        for (int i = 0; i < n; i++){
            cin >> a;
            if (a == 0) cnt++;
            s += a;
        }
        if (cnt != 0) s += cnt;
        if (s == 0) cnt++;
        cout << cnt << "\n";
    }
}
分享本文 Share with friends