CCF-CSP认证 201909-2小明种苹果(续)

CCF-CSP认证 201909-2小明种苹果(续)

#include 
using namespace std;

int n, D, E;
bool flag[1005];
int a[1005];

int pre(int x){
    if (x == 0) return n - 1;
    else return x -1;
}
int succ(int x){
    if (x == n - 1) return 0;
    return x + 1;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i = 0;i < n; i++){
        int m;
        cin >> m;
        cin >> a[i];
        for (int j = 1; j < m; j++){
            int x;
            cin >> x;
            if (x > 0) {
                if (a[i] != x){
                    a[i] = x;
                    flag[i] = 1;
                }
            }
            else a[i] += x;
        }
    }
    long long tot = 0;
    for (int i = 0; i < n; i++) tot += a[i];
    for (int i = 0; i < n; i++) D += flag[i];
    for (int i = 0; i < n; i++){
        if (flag[pre(i)] && flag[i] && flag[succ(i)]) E++;
    }
    cout << tot << " " << D << " " << E << "\n";
    return 0;
}

你可能感兴趣的:(CCF-CSP认证)