列表

详情


NC25068. [USACO 2007 Mar L]Classroom Statistics

描述

Bessie's teacher hates calculating the cow's grades but loves typing numbers into a computer, however ineptly. Help her figure out each student's average grade while ignoring those grades with typing errors.
The input file has N (1 <= N <= 100) grades (-100 <= grade <= 100). Any grade that is 0 or below is a typographical error which should be treated as if it didn't exist at least as far as calculating the mean (i.e., ignore the input and do not count that grade when calculating the mean). The mean of a group of numbers is the sum of those numbers divided by the number of numbers.
Printing numbers with decimal places is problemmatic, so just multiply the mean by 10 and round it by adding 0.5 before converting it to an integer.
Every dataset has at least one proper grade in it.

输入描述

Line 1: A single integer: N
Lines 2..N+1: Line i+1 contains a single integer that is grade i for a cow.

输出描述

Line 1: A single line with a single integer

示例1

输入:

5
100
90
100
0
100

输出:

975

说明:

Five lines of input; four valid grades (#4 is invalid since it is 0)
(100 + 90 + 100 + 100) / 4 = 97.500; multiply by ten and round: int(10 * 97.5 +0.5) -> 975

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Python3 解法, 执行用时: 43ms, 内存消耗: 4556K, 提交时间: 2023-08-18 17:28:05

n, s, t = int(input()), 0, 0
for i in range(n):
    k = int(input())
    if k > 0:
        t += 1
        s += k
        
print(int(s / t * 10 + 0.5))

上一题