• Grade Point Average(除法小运算)


    As soon as Moca entered the university last year as a freshman, she was told that the competition is fierce and everyone was desperately trying to improve their grades. As a result, in the last academic term, Moca studied just as hard as she did in high school.
    
    The college will award scholarships based on the average score of the previous academic term. Unfortunately, someone has the same average score as Moca because the average score is calculated rounding down to only 11 decimal places. For example, Ran's average score is \frac{48}{5} \approx 9.6 
    5
    48
    ​
     ≈9.6 and Moca's average score is \frac{29}{3} \approx 9.6 
    3
    29
    ​
     ≈9.6, but apparently Moca's average score is higher.
    
    Can you help Moca calculate her average score rounding down to kk decimal places?
    
    Input
    The first line contains two integers n, kn,k (1 \le n, k \le 10^5)(1≤n,k≤10 
    5
     ) – the number of courses and the number of decimal places.
    
    The second line contains nn integers a_1, a_2, \dots, a_na 
    1
    ​
     ,a 
    2
    ​
     ,…,a 
    n
    ​
      (0 \le a_i \le 100)(0≤a 
    i
    ​
     ≤100) – the score of each course.
    
    Output
    Print one real number in a line that denotes Moca's average score. Notice that your answer must contain kk decimal places.
    
    Sample 1
    Inputcopy    Outputcopy
    3 10
    94 100 99
    97.6666666666
    View Problem

    swjtu—春季集训 - Virtual Judge (vjudge.net)

    思路:

    • 除法运算利用 /,%运算就行了
    #include <bits/stdc++.h>
    using namespace std;
    #define ri register int
    #define M 200005
    
    template <class G> void read(G &x)
    {
        x=0;int f=0;char ch=getchar();
        while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();}
        while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
        x=f?-x:x;
        return ;
    }
    
    int val[M];
    int n,m;
    int main(){
        
        
        read(n);read(m);
        long long ans=0;
        for(ri i=1;i<=n;i++)
        {
            int a;read(a);
            ans+=a;
        }
        long long tmp=ans%n;
        ans=ans/n;
        for(ri i=1;i<=m;i++)
        {
            tmp*=10;
            val[i]=tmp/n;
            tmp%=n;
        }
        printf("%lld.",ans);
        for(ri i=1;i<=m;i++)
        printf("%d",val[i]);
        
        
    }
    View Code
  • 相关阅读:
    [Angularjs]视图和路由(一)
    [Angularjs]ng-show和ng-hide
    解决UNIGUI字体太小的问题
    [FireDAC][Phys][MySQL] MySQL server has gone away
    unidbgrid列排序
    在盒子(2CCC)的日子
    咏南MORMOT中间件免费开源
    unidbgrid单元格操作
    国内安卓软件的恶劣环境
    DELPHI纤程的演示
  • 原文地址:https://www.cnblogs.com/Lamboofhome/p/16225404.html
Copyright © 2020-2023  润新知