Valid IP addresses

4.5

2 votes
Implementation, Approved, Basic Programming, Data Structures, Easy, Open, approved, Basics of Implementation
Problem

You are provided a string S. Your task is to determine whether the provided string is a valid IP address.

A valid IP address is determined based on the following rules:

  1. The IP address must exactly contain four non-empty parts that are separated by three dots. For example, 255.255.255.255.
  2. The decimal value of each part of the IP address should not exceed 255 and must not be less than zero.

Input format

The first and only line of the input contains the string S.

Note

  • The string must contain only numbers and the . symbol of the ASCII character set only.
  • All IP addresses must be in the decimal format, that is, base 10 notation only.

Output format

If the provided IP address is valid, then print YES. Otherwise, print NO.

Note: Print the output in a single line.

Constraints

1|S|64

Sample Input
255.255.255.0
Sample Output
YES
Time Limit: 0.4
Memory Limit: 64
Source Limit:
Explanation

The string contains exactly 4 non-empty parts and 3 dots. The value of each part is <=255 and >= 0.

Contributers:
Editor Image

?