#T773. 子网掩码

子网掩码

Description

Subnet Mask Calculation Method
 
A subnet mask is used to determine whether the IP addresses of any two computers belong to the same subnet.

The simplest way to understand it is that if the result of performing an AND operation between each computer's IP address and the subnet mask is the same, then these two computers are on the same subnet and can communicate directly. It's that simple.

See the following examples:

Example Calculation 1: aa
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 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 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 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. All are 192.168.0.0.

   Therefore, the computer will consider these three computers to be on the same subnet.

Input Format

The first line is the local IP address.

The second line is the subnet mask.

The third line is an integer N, indicating there are N IP addresses to follow.

The 1st IP address

......

The Nth IP address

Output Format

Calculate and output whether the N IP addresses are on the same subnet as the local machine.

For those on the same subnet, output "INNER".

For those on different subnets, 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