首先输入要输入的整数个数n,然后输入n个整数。输出为n个整数中负数的个数,和所有正整数的平均值,结果保留一位小数。
0即不是正整数,也不是负数,不计入计算。如果没有正数,则平均值为0。
数据范围: ,输入的整数都满足
首先输入一个正整数n,
然后输入n个整数。
输出负数的个数,和所有正整数的平均值。
11 1 2 3 4 5 6 7 8 9 0 -1
1 5.0
3 0 0 0
0 0.0
while True: try: str1 = input()#记录没用的玩意儿 str2 = input().split()#记录有用的玩意儿,以空格区分 str2=list(map(int, str2))#转换为int格式 c1 = 0 c2 = 0 total = 0 for i in range (len(str2)):#遍历 if str2[i] >0:#为正时 c1 = c1 + 1#正数数量+1 total = total +str2[i] #正数总和相加 elif str2[i] <0:#为负时 c2 = c2 +1#负数数量加一 if c1 != 0:#总和不为零时 avg = total / c1 #得出平均值 avg = format(avg,'.1f') #保留一位小数 else: avg =0 str3 = str(c2)+ " " + str(avg)#打印出来 print(str3) except: break
while True:
try:
n=input()
m=input().split()
count=0
zheng=0
sum=0
for i in m:
if int(i)<0:
count+=1
for j in m:
if int(j)>0:
sum+=int(j)
zheng+=1
a=sum/zheng
print(str(count)+' '+str('%.1f'%a))
except:
break
while True: try: num = int(input()) ints = list(map(int, input().split())) nums_pos = list(filter(lambda x: x>0, ints)) nums_neg = list(filter(lambda x: x<0, ints)) if len(nums_neg) == len(ints): print(len(nums_neg), 0) else: print(len(nums_neg), format(sum(nums_pos)/len(nums_pos), '.1f')) except EOFError: break
while True: try: n, nums = int(input()), map(int, input().split()) negative_count, positive_count, posivive_sum = 0, 0, 0 for n in nums: if n < 0: negative_count += 1 elif n > 0: positive_count += 1 posivive_sum += n print("{} {:.1f}".format(negative_count, posivive_sum/positive_count)) except: break
while True: try: n, neg_count, pos_list = int(input().strip()), 0, [] nums = map(int, input().strip().split(' ')) for num in nums: if num < 0: neg_count += 1 if num > 0: pos_list.append(num) if len(pos_list) == 0: avg = '0.0' else: # 格式化字符串的结果一定是字符串 avg = '%.1f' % (sum(pos_list)/len(pos_list)) print(str(neg_count) + ' ' + avg) except: break
while True: try: Num = int(input()) list1 = list(map(int,input().split())) positive_num = [] negative_num = [] for i in list1: if i > 0: positive_num.append(i) elif i < 0: negative_num.append(i) negative_count = len(negative_num) mean_positive = sum(positive_num)/len(positive_num) print(negative_count,'%.1f' % mean_positive) except: break
while True: try: k = int(input()) a = list(map(int,input().split())) n, s, z = 0, 0, 0 for i in range(len(a)): if a[i] < 0: n = n + 1 elif a[i] > 0: s += a[i] elif a[i] == 0: z += 1 print(n, end = ' ') print(round(s/(len(a)-n-z),1)) except: break
from functools import reduce while True: try: n = int(input()) num = list(map(int,input().split())) negative = [] positive = [] for i in num: if i < 0: negative.append(i) elif i > 0: positive.append(i) print(len(negative),end=' ') print(round(((reduce(lambda x,y:x+y,positive))/(len(positive))),1)) except: break
while True: try: n = int(input()) stack = list(map(int, input().split())) total = 0; select = [] for elem in stack: if elem < 0: total += 1 if elem>0: select.append(elem) average = sum(select) / (len(select)) print(total, end=' ') if sum(select)%(len(select))==0: print(int(average)) else: print('%.1f'%average) except: break
while True: try: n = eval(input()) L = [eval(i) for i in input().split()] L1 = [i for i in L if i > 0] #正数列表 L2 = [i for i in L if i < 0] #负数列表 print('{} {:.1f}'.format(len(L2), sum(L1) / len(L1))) except: break
while True: try: n = int(raw_input()) count = 0 count1 = 0 s=0.0 for data in raw_input().split(): if int(data) < 0: count +=1 elif int(data)>0: count1 +=1 s = s + int(data) print count,round(s/count1,1) except: break