> 文章列表 > 【C++笔试强训】第三十二天

【C++笔试强训】第三十二天

【C++笔试强训】第三十二天

🎇C++笔试强训


  • 博客主页:一起去看日落吗
  • 分享博主的C++刷题日常,大家一起学习
  • 博主的能力有限,出现错误希望大家不吝赐教
  • 分享给大家一句我很喜欢的话:夜色难免微凉,前方必有曙光 🌞。

在这里插入图片描述

💦🔥


选择题

💦第一题

在计算机网络中,TCP和UDP协议的相似之处是()

A 面向非连接的协议
B 面向连接的协议
C 其余选项都不对
D 传输层协议

两者对比

TCP协议:面向连接,可靠,面向字节流

UDP协议:无连接,不可靠,面向数据报

都是传输层协议

【C++笔试强训】第三十二天

这道题的答案是D


💦第二题

在 OSI 参考模型中能实现路由选择,拥塞控制与互联功能的层是()

A 物理层
B 网络层
C 数据链路层
D 应用层

【C++笔试强训】第三十二天

这道题的答案是B


💦第三题

在TCP/IP中,ICMP属于哪一层协议?

A IP
B PPP
C UDP
D TCP

【C++笔试强训】第三十二天

ppp是链路层协议

这道题的答案是A


💦第四题

在发送TCP接收到确认ACK之前,由其设置的重传计时器到时,这时发送TCP会()

A 重传重要的数据段
B 放弃该连接
C 调整传送窗口尺寸
D 向另一个目标端口重传数据

【C++笔试强训】第三十二天

由图可知

这道题的正确答案是A


💦第五题

下列哪项最恰当地描述了建立TCP连接时“第一次握手”所做的工作()

A “连接发起方”向“接收方”发送一个SYN-ACK段
B “接收方”向“连接发起方”发送一个SYN-ACK段
C “连接发起方”向目标主机的TCP进程发送一个SYN段
D “接收方”向源主机得到TCP进程发送一个SYN段作为应答

【C++笔试强训】第三十二天

这道题的答案是C


💦第六题

关于以下 URL 的描述错误的是()

A http表明使用TCP协议
B 又名统一资源定位符,方便确定一个资源,并表示它在哪里
C URL中隐藏了端口号,默认是80端口
D 访问URL可使用大写字母

URL 又名统一资源定位符,方便确定一个资源,并表示它在哪里,可以使用大写字母

这道题的答案是A


💦第七题

不属于交换机攻击的是()

A 目录遍历攻击
B MAC泛洪攻击
C VLAN攻击
D DHCP欺骗攻击

【C++笔试强训】第三十二天- 攻击原理
【C++笔试强训】第三十二天

这道题的答案是A


💦第八题

在下面给出的协议中,()是TCP/IP的应用层协议

A ARP和FTP
B DNS和SMTP
C RARP和DNS
D ICMP和IGMP

【C++笔试强训】第三十二天【C++笔试强训】第三十二天

这道题的答案是B


💦第九题

IP地址块为211.168.15.192/26、211.168.15.160/27和211.168.15.128/27三个地址块经聚合后可用地址
数为()

A 126
B 62
C 128
D 68

【C++笔试强训】第三十二天
【C++笔试强训】第三十二天

这道题的答案是A


💦第十题

以下不是合法HTTP请求方法的是()

A GET
B SET
C HEAD
D PUT

【C++笔试强训】第三十二天

这道题的答案是B


编程题

🔥第一题

题目:淘宝网店

【C++笔试强训】第三十二天

  • 题目解析

这是一个变相的日期计算器。只不过2、3、5、7、11月算1天,其他7个月算2天。

  • 解题思路

既然是一个变相的日期计算器,那就写一个日期计算器,然后加以修改即可。那么,日期计算器怎么写呢?

日期计算器的话,我们将会把日期计算分为三个部分:第一个不足一年的年份,最后一个不足一年的年份,和中间的足年年份。足年年份我们只需要判断闰年后加365或366就行了。不足年,我们就要求出这个日期是这一年的第
几天。假设要求的是1994年5月27日到2003年4月29日,那么,我们就要先求出5月27日是这一年的第几天,然后判断1994年不是闰年,不是,所以用365减去这个天数,就得到结果了。本题中第一天也要算,所以还要加上这一
天。然后再算出4月29日是2003年的第几天,就可以解决问题了。所以,我们需要一个函数,功能是给出一个年月日,求出这是这一年的第几天。

这些功能全部实现后,再去改造使得1、4、6、8、9、10、12月的天数翻倍,那么程序就全部完成了。

  • 代码演示
#include <cstdio>
#include <cmath>
#include <iostream>
//闰年判断函数
inline int leap_year(int year) {return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
//足年天数
inline int profit_of_year(int year) {return 2 * 31+ 1 * 28+ 1 * 31+ 2 * 30+ 1 * 31+ 2 * 30+ 1 * 31+ 2 * 31+ 2 * 30+ 2 * 31+ 1 * 30+ 2 * 31+ leap_year(year);
}
//判断这个月份是不是质数月
inline bool prime(int n) {return n == 2 || n == 3 || n == 5 || n == 7 || n == 11;
}
//求出一个日子是这一年的第几天
int profit_of_this_year(int year, int month, int day) {if (!prime(month)) {day *= 2;}while (--month) {switch (month) {case 1:case 8:case 10:case 12:day += 62;break;case 3:case 5:case 7:day += 31;break;case 4:case 6:case 9:day += 60;break;case 11:day += 30;break;case 2:day += 28 + leap_year(year);break;default:;}}return day;
}
int main() {int year1, month1, day1, year2, month2, day2;int count_profit = 0;while (std::cin >> year1 >> month1 >> day1 >> year2 >> month2 >> day2) {count_profit = 0;count_profit += profit_of_year(year1) -profit_of_this_year(year1, month1, day1 - 1);
//这里的day1 - 1虽然有可能会出现0日,但是实际2月0日就相当于1月31日,所以不影响结果。count_profit += profit_of_this_year(year2, month2, day2);if (year1 ==year2) { //避免起点和终点是同一年,如果是同一年,要减掉这一年的天数。count_profit -= profit_of_year(year1);}for (int i = year1 + 1; i < year2; i++) { //中间足年每一年的天数count_profit += profit_of_year(i);}std::cout << count_profit << std::endl;}return 0;
}

🔥第二题

题目:斐波那契风尾

【C++笔试强训】第三十二天

  • 题目解析

题目要求输出斐波那契数列的第n项,最容易写的方法就是用循环求出每一项了。而它要求的是后六位,那么我们只需要存储后六位就行了。

  • 解题思路

先求斐波那契数列在100000以内的每一项的后六位,然后需要的时候直接输出数组里的对应值即可。以下代码用通常的循环法解决。

  • 代码演示
#include <cstdio>
#include <cmath>
#include <iostream>
//闰年判断函数
inline int leap_year(int year) {return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
//足年天数
inline int profit_of_year(int year) {return 2 * 31+ 1 * 28+ 1 * 31+ 2 * 30+ 1 * 31+ 2 * 30+ 1 * 31+ 2 * 31+ 2 * 30+ 2 * 31+ 1 * 30+ 2 * 31+ leap_year(year);
}
//判断这个月份是不是质数月
inline bool prime(int n) {return n == 2 || n == 3 || n == 5 || n == 7 || n == 11;
}
//求出一个日子是这一年的第几天
int profit_of_this_year(int year, int month, int day) {if (!prime(month)) {day *= 2;}while (--month) {switch (month) {case 1:case 8:case 10:case 12:day += 62;break;case 3:case 5:case 7:day += 31;break;case 4:case 6:case 9:day += 60;break;case 11:day += 30;break;case 2:day += 28 + leap_year(year);break;default:;}}return day;
}
int main() {int year1, month1, day1, year2, month2, day2;int count_profit = 0;while (std::cin >> year1 >> month1 >> day1 >> year2 >> month2 >> day2) {count_profit = 0;count_profit += profit_of_year(year1) -profit_of_this_year(year1, month1, day1 - 1);
//这里的day1 - 1虽然有可能会出现0日,但是实际2月0日就相当于1月31日,所以不影响结果。count_profit += profit_of_this_year(year2, month2, day2);if (year1 ==year2) { //避免起点和终点是同一年,如果是同一年,要减掉这一年的天数。count_profit -= profit_of_year(year1);}for (int i = year1 + 1; i < year2; i++) { //中间足年每一年的天数count_profit += profit_of_year(i);}std::cout << count_profit << std::endl;}return 0;
}