c++编程题,电话号码,求和

本文提供了两个编程题目。第一题涉及将电话号码中的字母转换为对应的数字,去除重复并按字典序排列。第二题要求找出所有可能的数列组合,使它们的和等于给定的整数。
摘要由CSDN通过智能技术生成

问答题

问答题1:A,B 两台机器都正常工作, B 机器未监听任何端口.如果 A 机器向 B 机器 80 端口发送SYN包,会收到何种类型的回包?

A: ACK包
B: FIN包
C: 不会收到回包
D: RST包

提示:因为 B 机器 80 端口未打开,所以会发送一个 RST 包,另外请求超时 、提前关闭 、在一个已关闭的 socket 上收到数据也会发送RST 包,RST 是TCP 首部的标志位之一,具体含义是复位连接,也可表示拒绝连接.

问答题2:某学校获取到一个B类地址段,要给大家分开子网使用,鉴于现在上网设备急剧增多,管理员给每个网段进行划分的子网掩码设置为255.255.254.0,考虑每个网段需要有网关设备占用一个地址的情况下,每个网段还有多少可用的主机地址?

提示:由于网关设备占用一个地址,所以可用主机地址数为 29 -2 -1 = 509,其中 2 代表的是主机地址全是0和1的地址,这两个地址不能作为主机地址,全为 0 表示一个网段,全为 1 表示网络广播

问答题3:当我们在局域网内使用ping www.nowcoder.com时,哪种协议没有被使用?

A: ICMP
B: ARP
C: DNS
D: TCP

提示:因为 ping 后面跟的是域名,所以要先将域名转换为 IP 地址,即用到了 DNS 协议,获取到 IP 地址,在数据链路层时根据 MAC 地址传输的,所以要用到 ARP 解析服务,获取 MAC 地址;ping 功能是测试另一台主机是否可达,程序发送一份ICMP回显请求给目标主机,并等待返回ICMP回显应答(ICMP主要是用于 IP 主机、路由器之间传递控制信息,控制信息是指网络通不通,主机是否可达),并没有用到TCP传输协议.

问答题4:某公司申请到一个C类IP地址,但要连接6个的子公司,最大的一个子公司有 26 台计算机,每个子公司在一个网段中,则子网掩码应设为?

提示:最大的子公司有 26 台计算机,可确认主机位数为 25,C 类默认的网络号为24位,27 - 24 = 3 位为子网号,23 = 8,除过全 1 和全 0 的子网号不能用,则可用的子网有 6 个,满足条件,所以子网掩码应设为 255.255.255.224

编程题

编程题1:电话号码

在这里插入图片描述

上图是一个电话的九宫格,如你所见一个数字对应一些字母,因此在国外企业喜欢把电话号码设计成与自己公司名字相对应,例如公司的Help Desk 号码是 4357,因为 4 对应 H 、3 对应 E、5 对应 L、7 对应 P,因此 4357 就是 HELP,同理,TUT-GLOP 就代表 888 - 4567、310 - GINO 代表 310 - 4466

NowCoder 刚进入外企,并不习惯这样的命名方式,现在给你一串电话号码列表,请你帮他转换成数字形式的号码,并去除重复的部分

输入描述:输入包含多组数据
每组数据第一行包含一个正整数 n(1≤n≤1024)

紧接着 n 行,每行包含一个电话号码,电话号码仅由连字符“-”、数字和大写字母组成。没有连续出现的连字符,并且排除连字符后长度始终为7(美国电话号码只有7位)

输出描述:对应每一组输入,按照字典顺序输出不重复的标准数字形式电话号码,即 “xxx-xxxx” 形式,每个电话号码占一行,每组数据之后输出一个空行作为间隔符

示例1:
输入
12
4873279
ITS-EASY
888-4567
3-10-10-10
888-GLOP
TUT-GLOP
967-11-11
310-GINO
F101010
888-1200
-4-8-7-3-2-7-9-
487-3279
输出:
310-1010
310-4466
487-3279
888-1200
888-4567
967-1111

案例2:
输入
4
UTT-HELP
TUT-GLOP
310-GINO
000-1213
输出
000-1213
310-4466
888-4357
888-4567

#include <iostream>
#include <unordered_map>
#include <string>
#include <set>
using namespace std;

int main(){
   
    unordered_map<char, char> dic;
    //可以用下标插入
    dic['A'] = '2';
    // 也可以使用 emplace 函数
    dic.emplace('B'
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
北京大学oj题目,已提交AC。原题目如下: Description Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the University of Waterloo by dialing the memorable TUT-GLOP. Sometimes only part of the number is used to spell a word. When you get back to your hotel tonight you can order a pizza from Gino's by dialing 310-GINO. Another way to make a telephone number memorable is to group the digits in a memorable way. You could order your pizza from Pizza Hut by calling their ``three tens'' number 3-10-10-10. The standard form of a telephone number is seven decimal digits with a hyphen between the third and fourth digits (e.g. 888-1200). The keypad of a phone supplies the mapping of letters to numbers, as follows: A, B, and C map to 2 D, E, and F map to 3 G, H, and I map to 4 J, K, and L map to 5 M, N, and O map to 6 P, R, and S map to 7 T, U, and V map to 8 W, X, and Y map to 9 There is no mapping for Q or Z. Hyphens are not dialed, and can be added and removed as necessary. The standard form of TUT-GLOP is 888-4567, the standard form of 310-GINO is 310-4466, and the standard form of 3-10-10-10 is 310-1010. Two telephone numbers are equivalent if they have the same standard form. (They dial the same number.) Your company is compiling a directory of telephone numbers from local businesses. As part of the quality control process you want to check that no two (or more) businesses in the directory have the same telephone number. Input The input will consist of one case. The first line of the input specifies the number of telephone numbers in the directory (up to 100,000) as a positive integer alone on the line. The remaining lines list the telephone numbers in the directory, with each number alone on a line. Each telephone number consists of a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. Exactly seven of the characters in the string will be digits or letters. Output Generate a line of output for each telephone number that appears more than once in any form. The line should give the telephone number in standard form, followed by a space, followed by the number of times the telephone number appears in the directory. Arrange the output lines by telephone number in ascending lexicographical order. If there are no duplicates in the input print the line: No duplicates. Sample Input 12 4873279 ITS-EASY 888-4567 3-10-10-10 888-GLOP TUT-GLOP 967-11-11 310-GINO F101010 888-1200 -4-8-7-3-2-7-9- 487-3279 Sample Output 310-1010 2 487-3279 4 888-4567 3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

程序猿的温柔香

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

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

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

打赏作者

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

抵扣说明:

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

余额充值