2018华为上机测试第二批

Posted 小河沟大河沟

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2018华为上机测试第二批相关的知识,希望对你有一定的参考价值。

  • AC三题,都比较基础主要考虑细节
    注意
while (cin >> num)
    {
        
        vec.push_back(num);
        if (cin.get() == '\n')
            break;

    }
  • 貌似可能只有华为编程题才合适我了
#include<iostream>
#include<math.h>

#include <vector>
#include <string>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>

#include <algorithm>
#include <functional>
#include <numeric> //accmulate


#include <fstream>
#include <iomanip>  //setprecision() setw()
using namespace std;

#define cin infile //一定不能再oj系统中,有错,导致超时等!!!
//C++文件输入
ifstream infile("in.txt", ifstream::in);

#include <limits>
#define INT_MIN     (-2147483647 - 1) /* minimum (signed) int value */
#define INT_MAX       2147483647    /* maximum (signed) int value */


#if 1

long long vec[21] = {0};
long long sum[17] = { 0 };
int main()
{

    for (int i = 0; i <= 20; i++)
    {
        cin >> vec[i];
    }
    for (int i = 0; i <= 21 - 4; i++)
    {
        sum[i] = vec[i] + vec[i + 1] + vec[i + 2] + vec[i + 3];
    }
    long long maxSum = 0;
    int index = 0;
    for (int i = 0; i <= 17;i++)
    {
        if (sum[i]>maxSum)
        {
            maxSum = sum[i];
            index = i;
        }
    }

    cout << index << endl;

    return 0;
}

//滑动遍历一次,结果只有80%,不知道为什么?
int main()
{
    for (int i = 0; i <= 20; i++)
    {
        cin >> vec[i];
    }
    long long sum = vec[0] + vec[1] + vec[2] + vec[3];

    long long maxsum = 0;
    int index = 0;
    for (int i = 1; i <= 21 - 4; i++)
    {
        long long temp = sum - vec[i - 1] + vec[i + 3];
        if (temp > maxsum)
        {
            maxsum = temp;
            index = i;
        }
        sum = temp;
    }
    cout << index << endl;

    return 0;
}

#endif


#if 1



#define max(a,b)    (((a) > (b)) ? (a) : (b))

long long  GetMaxSubsum(vector<long long > vec_)
{
    long long  tempSum = 0;
    long long  ret_sum = 0;
    if (vec_.size() <= 0)
    {
        return 0;
    }
    else
    {
        tempSum = vec_[0];
        ret_sum = vec_[0];
        for (int i = 1; i < vec_.size(); i++)
        {
            tempSum = (tempSum < 0) ? vec_[i] : (tempSum + vec_[i]);
            ret_sum = max(tempSum, ret_sum);
        }
        return ret_sum;
    }
    return ret_sum;
}

int main()
{
    
    long long  num;
    long long  ret = 0;
    vector<long long > vec;
    while (cin >> num)
    {
        
        vec.push_back(num);
        if (cin.get() == '\n')
            break;
    }

    ret = GetMaxSubsum(vec);
    cout << ret << endl;

    return 0;
}

    

#endif


#if 1

const int index[26] = { 16, 22, 4, 17, 19, 24, 20, 8, 14, 15, 0, 18, 3, 5, 6, 7, 9, 10, 11, 25, 23, 2, 21, 1, 13, 12 };
int main()
{

    string str;
    getline(cin, str);

    string output;
    for (int i = 0; i < str.size(); i++)
    {
        if (str[i] >= 65 && str[i] <= 90)
        {
            str[i] = index[str[i] - 65] + 65;
        }
        else if (str[i] >= 97 && str[i] <= 122)
        {
            str[i] = index[str[i] - 97] + 97;
        }
    }
    cout << str << endl;
    return 0;
}

#endif

以上是关于2018华为上机测试第二批的主要内容,如果未能解决你的问题,请参考以下文章

2018年美团春招(第二批)题解

2018秋招校招后端方向(第二批)

今日头条2018校招后端方向(第二批)第一题 二分查找

二分查找技巧---字节跳动2018校招算法方向(第二批)---用户喜好

DBA第二批面试已经开始,您准备好了吗?

软件测试第二次上机实验——Selenium的使用