#C14095. Valid IP Address Verification
Valid IP Address Verification
Valid IP Address Verification
You are given a string that represents an IP address. Your task is to determine whether it is a valid IP address.
An IP address is considered valid if it satisfies the following criteria:
- It consists of four segments (octets) separated by a single period
.
. - Each segment is a decimal number between 0 and 255, inclusive.
- Each segment must not contain leading zeros (except for the number zero itself).
For example, the IP address 192.168.1.1
is valid, whereas 192.168.1.01
is invalid because of the extra zero in the last segment.
You should read the input from stdin and output the result to stdout. Output True
if the IP address is valid, or False
otherwise.
The solution may involve parsing the string and performing checks on each segment with the constraints mentioned above. Use proper formatting for any mathematical expressions in LaTeX if they occur (e.g. \( 0 \leq segment \leq 255 \)).
inputFormat
The input consists of a single line containing a string representing the IP address. This input is read from stdin.
outputFormat
Output a single line to stdout containing either True
if the IP address is valid, or False
if it is not.
192.168.1.1
True