#include<bits/stdc++.h> using namespace std; int main() { int n,sum = 0,cnt = 0; //sum求和,cnt正數個數 cin >> n; for(int i = 1; i <= n; i++) { int x; cin >> x; if(x > 0) //正數 { sum += x; //累加 cnt++; //計數 } } cout << sum << endl << cnt; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n,sum = 0,cnt = 0; //sum求和,cnt正數個數 cin >> n; for(int i = 1; i <= n; i++) { int x; cin >> x; if(x > 0) //正數 { sum += x; //累加 cnt++; //計數 } } cout << sum << endl << cnt; return 0; }