华为2016校招机试题(2015年9月) 海大上午场(包含实现代码,运行环境为VS2010)

来源:互联网 发布:河北网络分销商查询 编辑:程序博客网 时间:2024/05/16 04:53
简单的均值滤波算法描述:计算机在对模拟信号进行数据采集时,经常会受到干扰,导致读取的数据发生突变。这时就需要对采集的数据做特殊处理。该题目模拟对电池电压的数据采集,限定条件如下: (1)电池电压的有效范围为【3300-4200】,包括3300和4200,无效值在计算时要丢弃 (2)输入为10组电池电压。包括有效值和无效值,每五组有效电压求一次平均值,作为最终输出值,有效值不够5组不输出 (3)输出的格式为“有效电压组数 平均值1 平均值2”。平均值有几组就输出几组,没有的话不输出。 (4)计算直接考虑整型数据即可,不考虑浮点数 除是输出外,中间不需要有任何的IO数据输出 运行时间限制:无限制 内存限制:无限制 输入:10组电压,为整型数据 输出:输出的格式为:“有效电压组数 平均值1 平均值2”,平均值有几组输出几组,没有的话不输出。“有效电压组数”必须输出
#include <iostream>using namespace std;const int cn = 10;//10组电压数据int main(){    int data[cn];  //10组电池电压    int sum=0;       //电压的总和    int aver[cn/5];//电压平均值    int count=0;    int ave=0;//平均值的个数    for (int i = 0; i < cn; i++)    {        cin >> data[i];    }    for (int i = 0; i < cn; i++)    {        if (data[i] >= 3300 && data[i] <= 4200)        {            sum += data[i];            count++;        }        if (count % 5==0 && count !=0)//统计有效电压值的数量能被5整除,但同时排除0        {            aver[ave] = sum / 5;            ave++;            sum = 0;        }    }    if (ave == 0)    {        cout << count << endl;        system("pause");        return 0;    }    cout << count << " ";    for (int i = 0; i < ave; i++)    {        cout << aver[i]<<"";    }    cout << endl;    system("pause");    return 0;}

描述:输入5个国名,并按字母顺序排列后输出
运行时间限制:无限制
内存限制:无限制
输入:输入5个国家名(英文大写),以空格分隔
输出:输出排序后的国名列表
样例输入:CHINA AMERICA AUSTRALIA FRANCE GERMAN
样例输出:
AMERICA
AUSTRALIA
CHINA
FRANCE
GERMAN

#include <iostream>#include <string>using namespace std;const int num = 5;int main(){    string country[num];    for (int i = 0; i < num; i++)    {        cin >> country[i];    }    for (int j = 0; j < num-1; j++)    {        for (int i = 0; i < num - 1 - j; i++)        {            if (country[i]>country[i + 1])            {                string temp = country[i];                country[i] = country[i + 1];                country[i+1] = temp;            }        }    }    for (int i = 0; i < num; i++)        cout << country[i] << " ";    system("pause");    return 0;}
0 0
原创粉丝点击