强训第37天

选择

B

D

D

网络号最高才247开头

主机号全为0是网络号

D

28位网络号 则第四个字节是1111 0000(240) 按位与91得80(0101 0000)

最大就是后面四个主机号全为1即80+15=95而且是广播IP

或者全部拿来比一下网络号

B

首先发数据肯定从低到高发。网络中要转成大端字节序。

在x86平台上为小端存储在内存上由低到高位12 34 56 78,转为大端变成 78 56 34 12

所以顺序是78 56 34 12

A

主机号占九位 2^9=512 减网络号 广播 和网关设备 =509

D

子网掩码要是连续的

D

DNS用的UDP

A

D

需要六个子网 所以需要至少3位充当网络号 所以剩了5个比特位充当主机号(2^5>26)符合

所以第四个字节的前三个字节是1 1110 0000为224

编程

数据库连接池

数据库连接池__牛客网

cpp 复制代码
#include <iostream>
#include <string.h>
#include <vector>
#include <string>
using namespace std;

int main() 
{
    int n;
    while(cin>>n)
    {
        string num,op;
        int res=0;
        int have=0;
        for(int i=0;i<n;i++)
        {
            cin>>num>>op;
            if(op=="connect")
            {
                if(have==0) res++;
                else have--;
            }
            else
            {
                have++;
            }
        }
        cout<<res<<endl;
    }
    return 0;
}

mkdir

mkdir__牛客网

cpp 复制代码
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() 
{
    int n;
    while(cin>>n)
    {
        vector<string>strs(n);
        vector<bool>exist(n,true);
        for(int i=0;i<n;i++) 
        {
            // getline(cin,strs[i]);
            // getline会把空格也识别上来 慎用
            cin>>strs[i];
        }
        sort(strs.begin(),strs.end());
        for(int i=0;i<n-1;i++)
        {
            if(strs[i]==strs[i+1])
            {
                exist[i]=false;
            }
            else if(strs[i]==strs[i+1].substr(0,strs[i].size()) && strs[i+1][strs[i].size()] == '/')
            {
                exist[i]=false;
            }
        }
        string tmp="mkdir -p ";
        for(int i=0;i<strs.size();i++)
        {
            if(exist[i])
            {
                cout<<tmp<<strs[i]<<endl;
            }
        }
        cout<<endl;
    }
    return 0;
}
相关推荐
saltymilk15 小时前
C++ 模板参数推导问题小记(模板类的模板构造函数)
c++·模板元编程
感哥16 小时前
C++ lambda 匿名函数
c++
沐怡旸1 天前
【底层机制】std::unique_ptr 解决的痛点?是什么?如何实现?怎么正确使用?
c++·面试
感哥1 天前
C++ 内存管理
c++
博笙困了1 天前
AcWing学习——双指针算法
c++·算法
感哥1 天前
C++ 指针和引用
c++
感哥2 天前
C++ 多态
c++
沐怡旸2 天前
【底层机制】std::string 解决的痛点?是什么?怎么实现的?怎么正确用?
c++·面试
River4162 天前
Javer 学 c++(十三):引用篇
c++·后端
感哥2 天前
C++ std::set
c++