#C10200. Validation of IPv4 Address with Subnet Mask
Validation of IPv4 Address with Subnet Mask
Validation of IPv4 Address with Subnet Mask
You are given a string that represents an IPv4 address with a subnet mask. The valid format is x.x.x.x/y
where each x
is a decimal number and y
is the subnet mask.
The rules for validity are:
- Each
x
must satisfy \(0 \leq x \leq 255\). - The subnet mask
y
must satisfy \(0 \leq y \leq 32\). - The IP address must consist of exactly four parts separated by dots, and the subnet mask must be provided after a single slash.
For example:
192.168.1.1/24
is valid.256.256.256.256/33
is invalid.
Your task is to implement a program that reads an input string from standard input, determines whether it is a valid IPv4 address with a subnet mask, and prints True
if it is valid or False
if it is not.
inputFormat
The input consists of a single line string from stdin that represents the IPv4 address with its subnet mask in the format x.x.x.x/y
.
outputFormat
Output a single line to stdout: print True
if the string is a valid IPv4 address with subnet mask, otherwise print False
.
192.168.1.1/24
True