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 representa
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.
标签: HBC52023Jerry 广度优先搜索(BFS) 搜索 背包问题 动态规划Shorten IPv6 Address题解