250B.md (3263B)
1 Source: https://codeforces.com/problemset/problem/250/B 2 3 B. Restoring IPv6 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 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. 22 23 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. 24 25 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. 26 27 You can see examples of zero block shortenings below: 28 29 * "a56f:00d3:0000:0124:0001:0000:0000:0000" → "a56f:00d3:0000:0124:0001::"; 30 * "a56f:0000:0000:0124:0001:0000:1234:0ff0" → "a56f::0124:0001:0000:1234:0ff0"; 31 * "a56f:0000:0000:0000:0001:0000:1234:0ff0" → "a56f:0000::0000:0001:0000:1234:0ff0"; 32 * "a56f:00d3:0000:0124:0001:0000:0000:0000" → "a56f:00d3:0000:0124:0001::0000"; 33 * "0000:0000:0000:0000:0000:0000:0000:0000" → "::". 34 35 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. 36 37 The format of the record of the IPv6 address after removing the leading zeroes and shortening the zero blocks is called short. 38 39 You've got several short records of IPv6 addresses. Restore their full record. 40 41 Input 42 43 The first line contains a single integer *n* — the number of records to restore (1 ≤ *n* ≤ 100). 44 45 Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:". 46 47 It is guaranteed that each short address is obtained by the way that is described in the statement from some full IPv6 address. 48 49 Output 50 51 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. 52 53 Examples 54 55 Input 56 57 ``` 58 6 59 a56f:d3:0:0124:01:f19a:1000:00 60 a56f:00d3:0000:0124:0001:: 61 a56f::0124:0001:0000:1234:0ff0 62 a56f:0000::0000:0001:0000:1234:0ff0 63 :: 64 0ea::4d:f4:6:0 65 ``` 66 67 Output 68 69 ``` 70 a56f:00d3:0000:0124:0001:f19a:1000:0000 71 a56f:00d3:0000:0124:0001:0000:0000:0000 72 a56f:0000:0000:0124:0001:0000:1234:0ff0 73 a56f:0000:0000:0000:0001:0000:1234:0ff0 74 0000:0000:0000:0000:0000:0000:0000:0000 75 00ea:0000:0000:0000:004d:00f4:0006:0000 76 ```