码迷,mamicode.com
首页 > 其他好文 > 详细

2018华为上机测试第二批

时间:2018-03-28 22:02:06      阅读:312      评论:0      收藏:0      [点我收藏+]

标签:dex   txt   ios   为什么   namespace   maximum   end   cin   nim   

  • 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华为上机测试第二批

标签:dex   txt   ios   为什么   namespace   maximum   end   cin   nim   

原文地址:https://www.cnblogs.com/ranjiewen/p/8666145.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!