#T570. 子网掩码
子网掩码
Description
Subnet Mask Calculation Method
A subnet mask is used to determine whether any two computers' IP addresses belong to the same subnet.
The simplest way to understand it is that if the results of performing an AND operation between each computer's IP address and the subnet mask are the same, it means these two computers are on the same subnet and can communicate directly. It's that simple.
See the following examples:
Example Calculation 1:
IP Address: 192.168.0.1
Subnet Mask: 255.255.255.0
AND Operation
Convert to binary for calculation:
IP Address: 11010000.10101000.00000000.00000001
Subnet Mask: 11111111.11111111.11111111.00000000
AND Operation
11010000.10101000.00000000.00000000
Converted back to decimal:
192.168.0.0
Example Calculation 2:
IP Address: 192.168.0.254
Subnet Mask: 255.255.255.0
AND Operation
Convert to binary for calculation:
IP Address: 11010000.10101000.00000000.11111110
Subnet Mask: 11111111.11111111.11111111.00000000
AND Operation
11010000.10101000.00000000.00000000
Converted back to decimal:
192.168.0.0
Example Calculation 3:
IP Address: 192.168.0.4
Subnet Mask: 255.255.255.0
AND Operation
Convert to binary for calculation:
IP Address: 11010000.10101000.00000000.00000100
Subnet Mask: 11111111.11111111.11111111.00000000
AND Operation
11010000.10101000.00000000.00000000
Converted back to decimal:
192.168.0.0
After performing the AND operation on the three sets of computer IP addresses and subnet masks above, we can see that the results are the same: 192.168.0.0.
Therefore, the computer will consider these three computers to be on the same subnet.
Input Format
First line: Local IP address
Second line: Subnet mask
Third line: Integer N, indicating the number of IP addresses that follow
IP Address 1
......
IP Address N
Output Format
Calculate and output whether each of the N IP addresses is on the same subnet as the local machine.
For IPs on the same subnet, output "INNER"
For IPs on a different subnet, output "OUTER"
```input1 192.168.0.1 255.255.255.0 3 192.168.0.2 192.168.0.254 192.168.1.2```output1
INNER
INNER
OUTER
译文
CodesOnline