#K37767. Valid IPv4 Address Checker
Valid IPv4 Address Checker
Valid IPv4 Address Checker
Your task is to determine whether a given string represents a valid IPv4 address.
An IPv4 address is composed of exactly four segments separated by periods. Each segment must satisfy the following conditions:
- It should be a non-negative integer within the range \(0\) to \(255\).
- If a segment consists of more than one digit, it must not have leading zeros (i.e. "0" is allowed only as a single digit).
For example, the address 192.168.1.1
is valid, but 192.168.01.1
is not valid because the second segment has a leading zero.
You need to read the input from standard input and output the result to standard output.
inputFormat
The input consists of a single line containing a string representing an IPv4 address.
Example:
192.168.1.1
outputFormat
Output a single line: True
if the input string is a valid IPv4 address; otherwise, output False
.
Example:
True## sample
192.168.1.1
True
</p>