-
Notifications
You must be signed in to change notification settings - Fork 3
/
816.cpp
51 lines (49 loc) · 1.48 KB
/
816.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Solution {
public:
vector<string> addPoint(string s) {
vector<string> res;
if (s.size() == 1) {
res.push_back(s);
return res;
}
int zeroCnt = 0;
for (auto& c : s) {
if (c == '0') zeroCnt++;
}
if (zeroCnt == 0) {
int n = s.size();
res.push_back(s);
for (int i = 1; i < n; ++i) {
res.push_back(s.substr(0, i) + "." + s.substr(i));
}
return res;
}
if (zeroCnt == s.size()) return {};
// zeroCnt >= 1
int n = s.size();
if (s[0] == '0' && s[n - 1] != '0') return {"0." + s.substr(1)};
if (s[0] == '0' && s[n - 1] == '0') return {};
if (s[0] != '0' && s[n - 1] == '0') return {s};
res.push_back(s);
for (int i = 1; i < n; ++i) {
res.push_back(s.substr(0, i) + "." + s.substr(i));
}
return res;
}
vector<string> ambiguousCoordinates(string s) {
vector<string> res;
s = s.substr(1);
s = s.substr(0, s.size() - 1);
int n = s.size();
for (int i = 1; i < n; ++i) {
vector<string> left = addPoint(s.substr(0, i));
vector<string> right = addPoint(s.substr(i));
for (auto& l : left) {
for (auto& r : right) {
res.push_back("(" + l + ", " + r + ")");
}
}
}
return res;
}
};