← 返回 openai 的题目列表Restore Valid IPv4 Addresses
类型:online_judge
Problem: Restore Valid IPv4 Addresses
Given a string s containing only digits, return all possible valid IPv4 addresses that can be formed from it.
A valid IPv4 address consists of 4 decimal segments separated by dots. Each segment must satisfy:
Its numeric value is between 0 and 255;
It must not contain leading zeros, unless the segment itself is exactly "0";
All characters in the input string must be used exactly once and in the original order.
Print all valid addresses in lexicographical order, one per line. If no valid address exists, print nothing.
Input
A single line containing string s.
Output
All valid IPv4 addresses, one per line, sorted lexicographically.
Constraints
1 <= len(s) <= 20
s contains only digits.
Example
Input:
25525511135
Output:
255.255.11.135
255.255.111.35
Example
Input
25525511135
Output
255.255.11.135
255.255.111.35