# LeetCode: 816. 模糊坐标¶

## 1、题目描述¶

输入: "(123)"



输入: "(00011)"

0.0, 00, 0001 或 00.01 是不被允许的。


输入: "(0123)"



输入: "(100)"

1.0 是不被允许的。


• 4 <= S.length <= 12.
• S[0] = "(", S[S.length - 1] = ")", 且字符串 S 中的其他元素都是数字。

## 2、解题思路¶

• 首先进行左右分割，然后对左右两部分判断有几个整数和小数
• 然后对左右两个数组进行笛卡尔积得到所有的情况
• 对每一个分割情况都进行上述操作

from itertools import product

class Solution:
def ambiguousCoordinates(self, S: str) -> List[str]:
ans = []

source = S[1:-1]
length = len(source)

for i in range(1, length):
left = []
right = []
if i == 1:
left.append(source[:i])
else:
if source[0] != "0":
left.append(source[:i])
if source[i - 1] != "0":
left.append(source[0] + "." + source[1:i])

if source[0] != "0":
for pos in range(2, i):
left.append(source[:pos] + "." + source[pos:i])
if i == length - 1:
right.append(source[i:])
else:
if source[i] != "0":
right.append(source[i:])
if source[-1] != "0":
right.append(source[i] + "." + source[i + 1:])
if source[i] != "0":
for pos in range(i + 2, length):
right.append(source[i:pos] + "." + source[pos:])

if left and right:
for l, r in product(left, right):
ans.append("(" + l + ", " + r + ")")
return ans