NC221176. GradePointAverage
描述
输入描述
The first line contains two integers -- the number of courses and the number of decimal places.The second line contains integers -- the score of each course.
输出描述
Print one real number in a line that denotes Moca's average score. Notice that your answer must contain decimal places.
示例1
输入:
3 10 94 100 99
输出:
97.6666666666
C++ 解法, 执行用时: 28ms, 内存消耗: 548K, 提交时间: 2021-08-01 14:45:15
#include <iostream> #include <cmath> using namespace std; int main(){ int n,k,s=0,a,i; cin>>n>>k; for(i=0;i<n;i++){cin>>a;s=s+a;} printf("%d.",s/n); s=s%n; for(i=0;i<k;i++){s=s*10; printf("%d",s/n); s=s%n;} }
Python3(3.9) 解法, 执行用时: 252ms, 内存消耗: 11384K, 提交时间: 2021-05-10 11:11:19
n,k=map(int, input().split()) a = sum([int(n) for n in (input().split())]) a=a*pow(10,k)//n a=str(a) while len(a)<=k: a="0"+a i=len(a)-k print(a[0:i],".",a[i:],sep="")