• 现场编码题目1


    1.现场编码题目:

    某比赛当中,有7个评委给张三选手打分,假设评委打分依次是 6,9,7,9,7,4,8
    -------------
    1.把此评委的分数依次从大至小排序并显示;
    2.显示最高分,最低分;
    3.显示去掉上方的一个最高分及一个最低分的平均值;
    4.把上述的7个评委已排序分数以及上述A、B、C的三个结果(最高分、最低分、平均值)都写到一个文件当中;
    ----------------------------------------------------------
    A.把上方的编码步骤用软件流程框图表达,用Word或Wps绘制。
    B.用编码实现上述1-4的所有要求。编码算法规则,没有限制。

    参考代码 Python版:

    pwList=[6,9,7,9,7,4,8]
    pwList.sort(reverse=True)
    print(pwList)
    pwMax=max(pwList)
    pwMin=min(pwList)
    pwSum=sum(pwList)
    pwAvg=(pwSum-pwMin-pwMax)/(len(pwList)-2)
    print("max:",pwMax,"min:",pwMin,"average:",pwAvg)
    with open('data.txt','w') as fp:
        for e in pwList:
            fp.write(str(e))
            fp.write("\n")
        fp.write("----------------\n")
        fp.write(str(pwMax))
        fp.write("\n")
        fp.write(str(pwMin))
        fp.write("\n")
        fp.write(str(pwAvg))    

     参考代码 C#版:

    using System;
    using System.IO;
    
    namespace Case1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] pwArray= { 6, 9, 7, 9, 7, 4, 8 };
                string[] pwArrayString = new string[11];
                Array.Sort(pwArray);
                Array.Reverse(pwArray);
                int maxPw = pwArray[0];
                int minPw = pwArray[6];
                int pwSum = 0;
                int i = 0;
                foreach(int e in pwArray)                
                {
                    Console.WriteLine(e);
                    pwArrayString[i] = e.ToString();
                    i++;
                    pwSum += e;
                }
                float pwAvg = (pwSum - maxPw - minPw) / (7 - 2);
                Console.WriteLine("max:{0},min:{1},avg:{2}", maxPw, minPw,pwAvg);
                pwArrayString[i] = "--------------";
                i++;
                pwArrayString[i] = maxPw.ToString();
                i++;
                pwArrayString[i] = minPw.ToString();
                i++;
                pwArrayString[i] = pwAvg.ToString();           
               File.WriteAllLines("data.txt", pwArrayString);         
                
    
            }
        }
    }

     参考代码 C++版:

    #include <iostream>
    #include<fstream>
    #include<algorithm>
    using namespace std;
    
    bool compare(int a, int b)
    {
        return b < a;
    }
    
    int main()
    {
        int pwArray[] = { 6,9,7,9,7,4,8 };
        sort(pwArray, pwArray + 7, compare);
        int intMax = pwArray[6], intMin = pwArray[0];
        int intSum=0;
        for (int i = 0; i < 7; i++)
        {
            cout << pwArray[i]<<"\n";
            intSum += pwArray[i];
        }
        double dblAvg=(intSum-intMax-intMin)/(7-2);    
        cout << "intMax:"<<intMax<<"  intMin:"<<intMin << "  dblAvg:"<<dblAvg;
        ofstream ofile;
        ofile.open("data.txt", ios::out);
        for (int i = 0; i < 7; i++)
        {
            ofile << pwArray[i] << "\n";
           
        }
        ofile <<"-------------------\n"<<"intMax:" << intMax << "  intMin:" << intMin << "  dblAvg:" << dblAvg;
        cout << "\nover";
    }
  • 相关阅读:
    EasyUI-datagrid-自动合并单元格(转)
    js中格式化时间字符串
    ext 3.2 tree 在IE10中点击事件失效的bug
    C#中修改Dll文件 (反编译后重新编译)
    GridView内容<br />换行
    使用Aspose.Words把 word转成图片
    判断移动设备访问自动跳转到移动版页面
    jquery mobile界面数据刷新
    Ubuntu16.04下安装Visual Studio Code
    npm 安装vue 报错Failed at the chromedriver@2.46.0 install script 'node install.js'
  • 原文地址:https://www.cnblogs.com/exesoft/p/16506837.html
Copyright © 2020-2023  润新知