#C10449. IP Address Validation

    ID: 39655 Type: Default 1000ms 256MiB

IP Address Validation

IP Address Validation

You are given a list of strings which represent IP addresses. Your task is to determine for each IP address whether it is valid or not.

An IP address is considered valid if it meets the following conditions:

  • The IP address consists of exactly four parts (called octets) separated by dots.
  • Each octet is a decimal number between 0 and 255 (inclusive).
  • Each octet must contain only digits (0-9). No extra leading characters or spaces are allowed.

For example, the IP address 192.168.0.1 is valid, while 256.100.50.25 is invalid because 256 is out of the allowed range.

Note: You are required to implement the solution by reading from the standard input (stdin) and writing to the standard output (stdout).

inputFormat

The first line of input contains a single integer N representing the number of IP addresses to validate. This is followed by N lines, each containing one IP address as a string.

Input Format:

N
ip_address_1
ip_address_2
...
ip_address_N

outputFormat

For each IP address, print a single line with either VALID or INVALID depending on whether the IP address meets the validation criteria.

Output Format:

result_1
result_2
...
result_N
## sample
4
192.168.0.1
255.255.255.255
0.0.0.0
1.1.1.1
VALID

VALID VALID VALID

</p>