• 华为招聘机试整理13:算分数的问题


    华为招聘机试整理13:算分数的问题

    题目:算分数的问题
    算分数的问题。去掉一个最高分一个最低分。之后求平均
    题目分析:
    直接利用#include<algorithm>中的sort排序。之后直接去除第一个和最后一个就能够了。最后精度考虑吧。我们这里用#include<iomanip>中的setiosflags(ios::fixed) << setpresicion(4)

    ==========================================================================
    參考代码:

    //算分数的问题.cpp
    //2014.7.11 hepanhui
    #include <iostream>
    #include <iomanip>
    #include <algorithm>
    using namespace std;
    
    float avescore(float score[],int n)
    {
        float sumscore = 0.0;
        float avescore = 0.0; 
        sort(score, score + n);
        for(int i = 1; i < n-1; i++)
        {
            sumscore += score[i]; 
        }
        avescore = sumscore/(n - 2);
        return avescore;
    }
    
    int main()
    {
        float score[6]={70,80,90,98,87,86}; 
        cout << setiosflags(ios::fixed) << setprecision(4) << avescore(score, 6) << endl;
        return 0;
    }
    
  • 相关阅读:
    枚举
    泛型
    装箱和拆箱
    使用TryParse()来执行数值转换
    参数数组
    checked和unchecked转换
    字符串不可变
    TCC : Tiny C Compiler (2018-2-6)
    win10 下 protobuf 与 qt
    QWebView 与Js 交互
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/6764334.html
Copyright © 2020-2023  润新知