#S0014. IP 地址检验

IP 地址检验

1. Description

Every device on the internet needs a unique IP address for communication. IPv4 is the most widely used address format, consisting of four dot-separated integers (0-255) with no leading zeros (e.g. "01.0.0.1" is invalid). Create an IPv4 address validator.

Background:

  • IPv4 addresses act as "digital house numbers" for devices
  • Format requirements: X.X.X.X where each X must:
    • Be 0-255 integer
    • Have no leading zeros if length >1
    • Contain only numeric characters

2. Input & Output

Input:

  • A single string
ip = input().strip()

Output:

  • "Valid" or "Invalid"

Example

# Input: 
172.16.254.1
# Output: 
Valid
# Input: 
192.0.0.256
# Output: 
Invalid
# Input: 
1e2.3.4.5
# Output: 
Invalid