-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathP_816.cpp
More file actions
39 lines (36 loc) · 902 Bytes
/
Copy pathP_816.cpp
File metadata and controls
39 lines (36 loc) · 902 Bytes
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
#include <bits/stdc++.h>
#define fast_io \
ios::sync_with_stdio(false); \
cin.tie(nullptr);
using namespace std;
vector<string> ambiguousCoordinates(string s) {
vector<string>* res = new vector<string>();
for (int i = 2; i < s.length() - 1; i++) {
for (string l : f(s.substr(1, i - 1))) {
for (string r : f(s.substr(i, s.length() - i - 1))) {
res->push_back("(" + l + ", " + r + ")");
}
}
}
return *res;
}
vector<string> f(string w) {
vector<string>* res = new vector<string>();
if (ok(w)) {
res->push_back(w);
}
if (w[w.length() - 1] == '0') {
return *res;
}
for (int i = 1; i < w.length(); i++) {
string l = w.substr(0, i);
string r = w.substr(i);
if (ok(l)) {
res->push_back(l + "." + r);
} else {
break;
}
}
return *res;
}
bool ok(string w) { return w.length() == 1 || w[0] != '0'; }