牛客网-华为2016校园招聘上机笔试题

第1题

在这里插入图片描述
在这里插入图片描述

我的代码,

#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>

using namespace std;

int a[30010];//学生初始成绩,从a[1]开始
int n, m;


int main()
{
    while(cin >> n >> m)
    {
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    
    int t = m;
    char op;
    while(m--)
    {
        cin >> op;
        if(op == 'Q')
        {
            int t1, t2;
            cin >> t1 >> t2;
            int val1 = min(t1, t2);
            int val2 = max(t1, t2);
            t1 = val1;
            t2 = val2;
            priority_queue<int> h;
            for(int i = t1; i <= t2; i++)
                h.push(a[i]);
            cout << h.top() << endl; 
        }
        else
        {
            int t1, t2;
            cin >> t1 >> t2;
            a[t1] = t2;
        }
        
    }
    }
    
    return 0;
}

第2题

在这里插入图片描述
在这里插入图片描述

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool cmp(pair<string, int> a, pair<string, int> b)
{
    return a.second > b.second;
}




int main() {

    vector<pair<string, int>> errors;
    string line, file;

    while(getline(cin, line))
    {
        int pos = line.rfind('\\') + 1;
        file = line.substr(pos);
        bool is_have = false;
        for(int i = 0; i < errors.size(); i++)
            if(errors[i].first == file)
            {
                errors[i].second++;
                is_have = true;
                break;
            }
        if(!is_have) errors.push_back({file, 1});
    }

    stable_sort(errors.begin(), errors.end(), cmp);

    for(int i = 0; i < 8 && i < errors.size(); i++)
    {
        string check = errors[i].first;
        int t = check.find(' ');
        if(t > 16) check.erase(0, t - 16);
        cout << check << ' ' << errors[i].second << endl;
    }

    return 0;

}

第3题

在这里插入图片描述
在这里插入图片描述

我写的代码,

//检查空格的数目,来确定手牌的数目
//输入已经保证合法性,不用检查输入是否是合法的牌。

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;


int main()
{
    string str;
    //cin >> str  //错误,不能这样使用,cin碰到空格或换行,就终止读入!!!
    getline(cin, str);
    
    if(str.find("joker JOKER") != -1)
    {
        cout << "joker JOKER" << endl;
        return 0;
    }
        
    int index = str.find('-');
    string str1 = str.substr(0, index);
    string str2 = str.substr(index+1);
    int num1 = count(str1.begin(), str1.end(), ' ');
    int num2 = count(str2.begin(), str2.end(), ' ');
    string world1 = str1.substr(0, str1.find(' '));
    string world2 = str2.substr(0, str2.find(' '));
    string s = "345678910JQKA2jokerJOKER";
    if(num1 == num2)
    {
        if(s.find(world1) > s.find(world2))
            cout << str1 << endl;
        else
            cout << str2 << endl;
    }
    else if(num1 == 3)
        cout << str1 << endl;
    else if(num2 == 3)
        cout << str2 << endl;
    else
        cout << "ERROR" << endl;
    
    
    
    return 0;    
}
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YMWM_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值