强训第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;
}
相关推荐
xlp666hub7 小时前
Leetcode第二题:用 C++ 解决字母异位词分组
c++·leetcode
不想写代码的星星8 小时前
static 关键字:从 C 到 C++,一篇文章彻底搞懂它的“七十二变”
c++
xlp666hub1 天前
Leetcode第一题:用C++解决两数之和问题
c++·leetcode
不想写代码的星星1 天前
C++继承、组合、聚合:选错了是屎山,选对了是神器
c++
不想写代码的星星2 天前
std::function 详解:用法、原理与现代 C++ 最佳实践
c++
樱木Plus4 天前
深拷贝(Deep Copy)和浅拷贝(Shallow Copy)
c++
blasit6 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_7 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星7 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛9 天前
delete又未完全delete
c++