首页 > 试题广场 >

统计数据正负个数

[编程题]统计数据正负个数
  • 热度指数:26629 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
输入10个整数,分别统计输出正数、负数的个数。

输入描述:
输入10个整数(范围-231~231-1),用空格分隔。


输出描述:
两行,第一行正数个数,第二行负数个数,具体格式见样例。
示例1

输入

-1 2 3 -6 7 8 -1 6 8 10

输出

positive:7
negative:3
x = tuple(map(int, input().split()))

z = tuple(filter(lambda x: x > 0, x))
f = tuple(filter(lambda x: x < 0, x))

print(f"positive:{len(z)}")
print(f"negative:{len(f)}")

发表于 2025-09-13 16:43:08 回复(0)
l = list(map(int,input().split()))
n = 0
m = 0
for i in l:
    if i >0:
        n = n+1
    else:
        m = m+1
print(f"positive:{n}")
print(f"negative:{m}")
发表于 2022-04-19 13:35:14 回复(0)
l = list(map(int, input().split()))
p,n = 0,0
for i in l:
    if i > 0:
        p += 1
    elif i < 0:
        n += 1
print('positive:{}\nnegative:{}'.format(p, n))

发表于 2022-03-26 18:41:38 回复(0)
while True:
    try:
        nums = list(map(int, input().split()))
        pos = 0
        neg = 0
        for i in nums:
            if i > 0:
                pos += 1
            else:
                neg += 1
        print('positive:{}'.format(pos), end='\n')
        print('negative:{}'.format(neg))
    except:
        break
发表于 2022-02-26 21:42:10 回复(0)
l = [int(i) for i in input().split()]
pos_c = 0
neg_c = 0

for n in l:
    if n > 0:
        pos_c += 1
    elif n < 0:
        neg_c += 1
    else:
        pass
print(f"positive:{pos_c}\nnegative:{neg_c}")

发表于 2021-07-22 08:38:37 回复(0)