CF250B.Restoring IPv6
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
IPv6 地址是一个 128 位的数字。为便于书写,该数字以十六进制形式按每块 16 位进行分组记录,各块之间用冒号 : 分隔——共 8 块,每块恰好包含 4 个十六进制数字。以下是一个合法 IPv6 地址的完整记录示例:"0124:5678:90ab:cdef:0124:5678:90ab:cdef"。我们将这种格式称为 IPv6 地址的完整格式。
除完整格式外,IPv6 地址还存在一种简写格式。简写格式允许从每个块的开头移除一个或多个前导零;但每个块在简写格式中至少须保留一位数字。例如,前导零可如下方式移除:"a56f:00d3:0000:0124:0001:f19a:1000:0000" → "a56f:d3:0:0124:01:f19a:1000:00"。该 IPv6 地址还可通过其他方式进一步缩短零。
某些 IPv6 地址包含连续的零块序列。连续的若干个 16 位全零块(即每个块的 16 位均为 0)可被缩写为 ::。该序列可仅含一个块,也可含多个连续块。
以下为零块缩写的若干示例:
"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"→"::"。
地址中零块的缩写至多只能进行一次,即简写格式中不允许出现多于一个 :: 序列;否则将无法唯一确定每个 :: 所代表的零块数量。
经移除前导零及缩写零块后得到的 IPv6 地址记录格式称为简写格式。
现给出若干 IPv6 地址的简写格式记录,请将其还原为完整格式。
输入格式
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.
第一行包含一个整数 n —— 需要还原的记录数量(1≤n≤100)。
接下来的 n 行,每行包含一个字符串 —— 短格式 IPv6 地址。每个字符串仅由字符 "0123456789abcdef:" 组成。
保证每个短格式地址均是按照题目描述的方法,由某个完整 IPv6 地址生成的。
输出格式
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.
对于输入中的每个简写的 IPv6 地址,请在单独一行上输出其完整形式。请按照输入中简写地址出现的顺序,依次输出其对应的完整形式。
输入输出样例
输入#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
输入解题思路,AI测评打分。不知道怎么写?