牛客网Day1

目录

一、选择题


二、编程题

2.1 组队竞赛


参考代码:

cpp 复制代码
#include <queue>

int main()
{
    priority_queue<int> pq;
    int n=0;
    cin>>n;
    int tmp=0;
    for(size_t i=0;i<3*n;i++)
    {
        cin>>tmp;
        pq.push(tmp);
    }
    long long sum=0;
    for(size_t i=0;i<n;i++)
    {
        pq.pop();
        //取第二大,第四大...,一共取n个求和
        sum+=pq.top();
        pq.pop();
    }
    cout<<sum<<endl;

    return 0;
}

2.2 删除公共字符


参考代码:

cpp 复制代码
int main()
{
    string str1;
    string str2;
    //不能用cin,因为cin遇到空格会结束
    //getline读取一行,以回车为结束符
    getline(cin,str1);
    getline(cin,str2);

    int hash[128]={0};
    for(const auto& e:str2)
    {
        //把str2的字符都映射到哈希表的对应位置上
        hash[e]++;
    }
    string ret;
    for(const auto& e:str1)
    {
        //如果str1中的值存在于str2中,那么我们就跳过,即在str1中
        //删除该元素否则,这个字符就是我们要保留的,+=到ret即可
        if(hash[e]==0)
        {
            ret+=e;
        }
    }
    cout<<ret<<endl;

    return 0;
}

你学会了吗?

相关推荐
沐怡旸16 小时前
【底层机制】std::unique_ptr 解决的痛点?是什么?如何实现?怎么正确使用?
c++·面试
感哥17 小时前
C++ 内存管理
c++
聚客AI17 小时前
🙋‍♀️Transformer训练与推理全流程:从输入处理到输出生成
人工智能·算法·llm
大怪v19 小时前
前端:人工智能?我也会啊!来个花活,😎😎😎“自动驾驶”整起!
前端·javascript·算法
惯导马工21 小时前
【论文导读】ORB-SLAM3:An Accurate Open-Source Library for Visual, Visual-Inertial and
深度学习·算法
骑自行车的码农1 天前
【React用到的一些算法】游标和栈
算法·react.js
博笙困了1 天前
AcWing学习——双指针算法
c++·算法
感哥1 天前
C++ 指针和引用
c++
moonlifesudo1 天前
322:零钱兑换(三种方法)
算法
感哥1 天前
C++ 多态
c++