IPv6
InterviewTime limit1sMemory limit128 MB
Given a shortened IPv6 address with omitted leading zeros and possibly one '::' run, expand it into eight full 4-digit hex groups.
- Level
Easy3 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
IPv6 is a next-generation Internet protocol whose addresses are 128 bits long.
An IPv6 address is written as 32 hexadecimal digits split into groups of 4 digits. Adjacent groups are separated by colons (:).
For example:
2001:0db8:85a3:0000:0000:8a2e:0370:7334
Because 32 hexadecimal digits are inconvenient for people to read and write, and many digits are usually zero, an IPv6 address may be shortened as follows.
- Some or all leading zeroes in each group may be omitted. The address above can be shortened to:
2001:db8:85a3:0:00:8a2e:370:7334
- If one or more consecutive groups consist only of zeroes, exactly one such consecutive run may be replaced by two colons (
::).
2001:db8:85a3::8a2e:370:7334
The second rule may be used only once, to avoid ambiguity.
Given a valid shortened IPv6 address, restore and print its original unshortened form as eight groups of four hexadecimal digits.
Input
The first line contains a valid IPv6 address. Its length is at most 39 characters, and it consists only of digits 0-9, lowercase letters a-f, and colons (:).
Output
Print the unshortened form of the given IPv6 address.