#606. 「Nowcoder多校 2019 Day6」Shorten IPv6 Address

「Nowcoder多校 2019 Day6」Shorten IPv6 Address

当前没有测试数据。

题目描述

You are given an IPv6 address which is a 128-bit binary string. Please determine its shortest representation according to the following rules: Express the address in hexadecimal representation and use a colon ':' to split every four hex digits. Every four digits are called a field. For example, '0000:0000:0123:4567:89ab:0000:0000:0000'. Leading zeros in a field can be omitted. For example, the above IPv6 address can be shortened to '0:0:123:4567:89ab:0:0:0'. Consecutive zero fields (with colons near them) consisting of at least two fields can be replaced by a double colon '::'. Besides, no more than one double colon can be used in an address. For example, the above IPv6 address can be shortened to '0:0:123:4567:89ab::' or '::123:4567:89ab:0:0:0', but not '::123:4567:89ab::'. If there are multiple shortest forms of the same length, use the lexicographically (regard the shorten IPv6 address as string) smallest one. If the above rules conflict with rules in the real world, please refer to the rules mentioned in this problem.

输入格式

There are multiple test cases. The first line contains an integer T (1T10001 \leq T \leq 1000), indicating the number of test cases. Test cases are given in the following.Each test case consists of only one line, containing a 128-bit binary string.

输出格式

For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1, and y denotes the answer to this test case.

样例

样例输入 1

3
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000010010001101000101011001111000100110101011000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000010010001100000000000000000000000000000000000000000000000001000101011001111000100110101011

样例输出 1

Case #1: ::
Case #2: 0:0:123:4567:89ab::
Case #3: 0:0:123::4567:89ab