301337: CF250B. Restoring IPv6

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Restoring IPv6

题意翻译

$\text{IPv6}$ 地址是一个 $128$ 位的数字,为方便起见,这个地址被记录在一个 $16$ 进制块中,被冒号分成 $8$ 个块。 例如 `0124:5678:90ab:cdef:0124:5678:90ab:cdef` 就是一个 $\text{IPv6}$ 的正确压缩的例子。我们称其为 $\text{IPv6}$ 地址的完整形式。 有时,我们又要缩写这样的 $\text{IPv6}$ 地址。有很多方式可以缩写地址,例如删除前导 $0$ (例如`a56f:00d3:0000:0124:0001:f19a:1000:0000` $\rightarrow$ `a56f:d3:0:0124:01:f19a:1000:00` ,当然还有其他方法删除这个 $\text{IPv6}$ 地址的前导 $0$ )、缩写连续 $0$ 序列(例如`a56f:00d3:0000:0124:0001:0000:0000:0000` $\rightarrow$ `a56f:00d3:0000:0124:0001::`,缩写后的连续 $0$ 序列用 $::$ 双冒号表示,注意每个 $\text{IPv6}$ 地址只能用一次 $::$ )。 这样缩写之后的 $\text{IPv6}$ 地址称为 $\text{IPv6}$ 地址的缩写形式。 现在给出 $n$ 个 $\text{IPv6}$ 地址的缩写形式,请你把其完整形式还原并输出。 输入第一行一个正整数 $n~(1 \leqslant n\leqslant 100)$ ,随后 $n$ 行,每行一个字符串,表示被缩写过后的 $\text{IPv6}$ 地址,保证只包含 $\text{0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,:}$ 十七个字符。 对于每个字符串,输出一行,表示对应的 $\text{IPv6}$ 地址的完整形式。

题目描述

An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef". We'll call such format of recording an IPv6-address full. Besides the full record of an IPv6 address there is a short record format. The record of an IPv6 address can be shortened by removing one or more leading zeroes at the beginning of each block. However, each block should contain at least one digit in the short format. For example, the leading zeroes can be removed like that: "a56f:00d3:0000:0124:0001:f19a:1000:0000" $ → $ "a56f:d3:0:0124:01:f19a:1000:00". There are more ways to shorten zeroes in this IPv6 address. Some IPv6 addresses contain long sequences of zeroes. Continuous sequences of 16-bit zero blocks can be shortened to "::". A sequence can consist of one or several consecutive blocks, with all 16 bits equal to 0. You can see examples of zero block shortenings below: - "a56f:00d3:0000:0124:0001:0000:0000:0000" $ → $ "a56f:00d3:0000:0124:0001::"; - "a56f:0000:0000:0124:0001:0000:1234:0ff0" $ → $ "a56f::0124:0001:0000:1234:0ff0"; - "a56f:0000:0000:0000:0001:0000:1234:0ff0" $ → $ "a56f:0000::0000:0001:0000:1234:0ff0"; - "a56f:00d3:0000:0124:0001:0000:0000:0000" $ → $ "a56f:00d3:0000:0124:0001::0000"; - "0000:0000:0000:0000:0000:0000:0000:0000" $ → $ "::". It is not allowed to shorten zero blocks in the address more than once. This means that the short record can't contain the sequence of characters "::" more than once. Otherwise, it will sometimes be impossible to determine the number of zero blocks, each represented by a double colon. The format of the record of the IPv6 address after removing the leading zeroes and shortening the zero blocks is called short. You've got several short records of IPv6 addresses. Restore their full record.

输入输出格式

输入格式


The first line contains a single integer $ n $ — the number of records to restore ( $ 1<=n<=100 $ ). Each of the following $ n $ lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:". It is guaranteed that each short address is obtained by the way that is described in the statement from some full IPv6 address.

输出格式


For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input.

输入输出样例

输入样例 #1

6
a56f:d3:0:0124:01:f19a:1000:00
a56f:00d3:0000:0124:0001::
a56f::0124:0001:0000:1234:0ff0
a56f:0000::0000:0001:0000:1234:0ff0
::
0ea::4d:f4:6:0

输出样例 #1

a56f:00d3:0000:0124:0001:f19a:1000:0000
a56f:00d3:0000:0124:0001:0000:0000:0000
a56f:0000:0000:0124:0001:0000:1234:0ff0
a56f:0000:0000:0000:0001:0000:1234:0ff0
0000:0000:0000:0000:0000:0000:0000:0000
00ea:0000:0000:0000:004d:00f4:0006:0000

Input

题意翻译

$\text{IPv6}$ 地址是一个 $128$ 位的数字,为方便起见,这个地址被记录在一个 $16$ 进制块中,被冒号分成 $8$ 个块。 例如 `0124:5678:90ab:cdef:0124:5678:90ab:cdef` 就是一个 $\text{IPv6}$ 的正确压缩的例子。我们称其为 $\text{IPv6}$ 地址的完整形式。 有时,我们又要缩写这样的 $\text{IPv6}$ 地址。有很多方式可以缩写地址,例如删除前导 $0$ (例如`a56f:00d3:0000:0124:0001:f19a:1000:0000` $\rightarrow$ `a56f:d3:0:0124:01:f19a:1000:00` ,当然还有其他方法删除这个 $\text{IPv6}$ 地址的前导 $0$ )、缩写连续 $0$ 序列(例如`a56f:00d3:0000:0124:0001:0000:0000:0000` $\rightarrow$ `a56f:00d3:0000:0124:0001::`,缩写后的连续 $0$ 序列用 $::$ 双冒号表示,注意每个 $\text{IPv6}$ 地址只能用一次 $::$ )。 这样缩写之后的 $\text{IPv6}$ 地址称为 $\text{IPv6}$ 地址的缩写形式。 现在给出 $n$ 个 $\text{IPv6}$ 地址的缩写形式,请你把其完整形式还原并输出。 输入第一行一个正整数 $n~(1 \leqslant n\leqslant 100)$ ,随后 $n$ 行,每行一个字符串,表示被缩写过后的 $\text{IPv6}$ 地址,保证只包含 $\text{0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,:}$ 十七个字符。 对于每个字符串,输出一行,表示对应的 $\text{IPv6}$ 地址的完整形式。

加入题单

上一题 下一题 算法标签: