Điểm:
100 (p)
Thời gian:
1.0s
Bộ nhớ:
1G
Input:
bàn phím
Output:
màn hình
Nhập vào một dãy \(N\) số nguyên \(A_{1},A_{2},...,A_{N}\).
Hãy in ra màn hình số lượng phần tử dương và tổng của chúng.
Input
- Dòng đầu tiên chứa số nguyên \(N\).
- \(N\) dòng tiếp theo chứa \(N\) số nguyên \(A_{1},A_{2},...,A_{N}\).
Output
- In ra số lượng phần tử dương và tổng của chúng.
Constraints
- \(1 \leq n \leq 10000\)
- \(|A_{i}| \leq 10^{9}\)
Example
Test 1
Input
7
7
-6
-4
19
-22
51
-82
Output
3 77
Bình luận
include <bits/stdc++.h>
using namespace std;
int a[10004];
int n;
long long x=0, z=0;
int main() {
cin >> n;
for (int i=1; i<=n; i++) {
cin >> a[i];
}
sort (a+1, a+n+1, greater<long long>());
for (int i=1; i<=n; i++) {
if (a[i]>0) {
x+=a[i];
z++;
}
else break;
}
cout << z << " " << x;
return 0;
}
AC
n=int(input())
tong=0
dem=0
for i in range(1,n+1):
a=int(input())
if a>0:
tong=tong+a
dem=dem+1
print(dem,tong)
code py3
đúng 100%
n=int(input())
s=0
d=0
for i in range (n):
x=int(input())
if(x>0):
s=s+x;
d=d+1
print(d,s)
n=int(input())
s=0
d=0
for i in range (n):
x=int(input())
if(x>0):
s=s+x;
d=d+1
print(d,s)
n=int(input())
s=0
d=0
for i in range (n):
x=int(input())
if(x>0):
s=s+x;
d=d+1
print(d,s)
n=int(input())
A=[]
for k in range(1,n+1):
a=int(input())
A.append(a)
tong=0
dem=0
for i in range(n):
if A[i]>0:
dem=dem+A[i]
tong=tong+1
print(tong,dem)
This comment is hidden due to too much negative feedback. Click here to view it.
Spoiler Alert
Hint 1
Hint 2
Online Solving
]