IP地址的计算问题,输出对IP地址判断的结果,谢谢

Problem Description
Professor X is an expert in network security. These days, X is planning to build a powerful network firewall, which is called Good Firewall (a.k.a., GFW). Network flows enter in the GFW will be forwarded or dropped according to pre-established forwarding policies.

Basically, a forwarding policy P is a list of IP subnets, {ip_subnet_1, …, ip_subnet_n}. If P is enabled in GFW, a network flow F with source and destination IP address both located in P can be accepted and forwarded by GFW, otherwise F will be dropped by GFW.

You may know that, an IP address is a 32-bit identifier in the Internet, and can be written as four 0~255 decimals. For example, IP address 01111011.00101101.00000110.01001110 can be expressed as 123.45.6.78. An IP subnet is a block of adjacent IP address with the same binary prefix, and can be written as the first IP address in its address block together with the length of common bit prefix. For example, IP subnet 01111011.00101101.00000100.00000000/22 (123.45.4.0/22) is an IP subnet containing 1024 IP addresses, starting from 123.45.4.0 to 123.45.7.255. If an IP address is in the range of an IP subnet, we say that the IP address is located in the IP subnet. And if an IP address is located in any IP subnet(s) in a policy P, we say that the IP address is located in the policy P.

How will you design the GFW, if you take charge of the plan?

Input
The input file contains no more than 32768 lines. Each line is in one of the following three formats:

E id n ip_subnet_1 ip_subnet_2 … ip_subnet_n
D id
F ip_src ip_dst

The first line means that a network policy Pid (1<=id<=1024) is enabled in GFW, and there are n (1<=n <=15) IP subnets in Pid. The second line means that policy Pid (which is already enabled at least once) is disabled in GFW. The last line means that a network flow with source and destination IP address is entered in GFW, and you need to figure out whether GFW is going to forward (F) or drop (D) this flow:

  1. If the source and destination IP address both are located in one of enabled policy group Pid, GFW will forward this flow.

  2. Otherwise GFW will drop this flow. That is, if the source or destination IP address is not located in any of enabled policy group, or they are only located in different enabled policy group(s), GFW will drop it.

IP subnets can be overlapped. An IP address may or may not be located in any policy group, and can also be located in multiple policy groups.

In the global routing table, most of the IP subnets have at least 2^8 IP addresses, and at most 2^24 IP addresses. In our dataset, every IP subnet has a prefix length between 8 and 24.

Output
For each ‘F’ operation, output a single ‘F’ (forward) or ‘D’ (drop) in a single line. Just see the sample output for more detail.

Sample Input
E 1 2 123.45.4.0/22 123.45.8.0/22
F 123.45.4.1 123.45.8.1
F 123.45.8.1 123.45.4.1
E 2 1 123.45.6.0/24
D 1
F 123.45.6.123 123.45.6.234
F 123.45.8.1 123.45.4.1

Sample Output
F
F
F
D

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

0
32位的整数的运算实现IP地址的算法,C语言的字符数组的运用怎么做
0
给定两个 IP 地址和子网掩码判断 IP 是否属于同一网段
3
在NAT模式下。对于虚拟机来说,主机的ip地址是什么?
1
Debian9.8如何配置trunk以及ip地址
1
centos7桥接后,自动生成的ip地址与主机的以太网适配器ip地址一致
0
IP的计算,用C语言计算
3
centos7 查看ip地址问题,修改配置文件后出错,求解决!!
0
关于 IP地址的问题
7
关于本地ip的问题,使用cmd的ipconfig命令出现多个IP地址
0
思科防火墙组怎么实现内网用户对外访问网络只使用一个ip地址的?
1
.bat文件没有从ip.txt中循环读取并输出结果,只是输出读取了第一行ip的结果。ip.txt每行一个ip地址。求助大神
1
无IP地址或IP地址冲突时的计算机之间的信息交换
2
MVC在IIS服务器获取用户IP地址
2
IP地址和域名的对应关系
2
一台本地服务器加公网ip怎么让web项目通过ip地址能够访问?
3
对于每一个输入,单独输出一行。如果该字符串是合法的IP,输出YES,否则, 输出NO
0
tracert程序编译成功运行后,无法正常发送接收包,输出结果只有123456789101112131415161718192021222324252627282930,不显示详细情况,单步运行后发现接收发送包的部分没执行
1
树莓派搭建wordpress的ip地址问题
2
服务器有外网ip也有内网ip,但是程序访问的时候总是外网ip